]> jfr.im git - irc/quakenet/qwebirc.git/blame - js/sound.js
don't die on beep with flash block
[irc/quakenet/qwebirc.git] / js / sound.js
CommitLineData
127631e0
CP
1qwebirc.sound.domReady = false;
2window.addEvent("domready", function() {
3 qwebirc.sound.domReady = true;
4});
5
6qwebirc.sound.SoundPlayer = new Class({
7 Implements: [Events],
8 initialize: function() {
9 this.loadingSWF = false;
10 this.loadedSWF = false;
11 },
12 go: function() {
13 if(qwebirc.sound.domReady) {
14 this.loadSoundManager();
15 } else {
16 window.addEvent("domready", function() {
17 this.loadSoundManager();
18 }.bind(this));
19 }
20 },
21 loadSoundManager: function() {
22 if(this.loadingSWF)
23 return;
24 this.loadingSWF = true;
25 if(eval("typeof soundManager") != "undefined") {
26 this.loadedSWF = true;
27 this.fireEvent("ready");
28 return;
29 }
30
5ad04c7b 31 var debugMode = false;
fbe5af77
CP
32 qwebirc.util.importJS(qwebirc.global.staticBaseURL + "js/" + (debugMode?"soundmanager2":"soundmanager2-nodebug-jsmin") + ".js", "soundManager", function() {
33 soundManager.url = qwebirc.global.staticBaseURL + "sound/";
127631e0 34
5ad04c7b
CP
35 soundManager.debugMode = debugMode;
36 soundManager.useConsole = debugMode;
127631e0
CP
37 soundManager.onload = function() {
38 this.loadedSWF = true;
39 this.fireEvent("ready");
40 }.bind(this);
41 soundManager.beginDelayedInit();
42 }.bind(this));
43 },
44 createSound: function(name, src) {
b27937f8
CP
45 try {
46 soundManager.createSound(name, src);
47 } catch(e) {
48 /* ignore... flashblock triggers this */
49 }
127631e0
CP
50 },
51 playSound: function(name) {
b27937f8
CP
52 try {
53 soundManager.play(name);
54 } catch(e) {
55 /* ignore... */
56 }
127631e0
CP
57 },
58 beep: function() {
59 if(!this.beepLoaded) {
fbe5af77 60 this.createSound("beep", qwebirc.global.staticBaseURL + "sound/beep3.mp3");
127631e0
CP
61 this.beepLoaded = true;
62 }
63 this.playSound("beep");
64 }
65});