Created
September 13, 2010 17:16
-
-
Save kourge/577659 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://developer.mozilla.org/En/Using_audio_and_video_in_Firefox#Media_events | |
// https://developer.mozilla.org/en/XPCOM_Interface_Reference/nsIDOMHTMLMediaElement | |
var Sounds = { | |
sounds: {}, | |
errors: [null, "ABORTED", "NETWORK", "DECODE", "SRC_NOT_SUPPORTED"], | |
register: function register(sounds) { | |
var errors = this.errors; | |
for (var i = 0, l = sounds.length; i < l; i++) { | |
var audio = new Audio(); | |
audio.autobuffer = true; | |
audio.autoplay = false; | |
audio.src = sounds[i].src; | |
audio.addEventListener("error", function(event) { | |
throw new Error("MEDIA_ERR_" + errors[audio.error.code]); | |
}, false); | |
audio.load(); | |
this.sounds[sounds[i].id] = audio; | |
} | |
}, | |
play: function play(id) { | |
var audio = this.sounds[id]; | |
if (!audio) | |
throw new Error("The id is not registered yet"); | |
audio.play(); | |
}, | |
pauseAll: function pauseAll() { | |
for (var i = 0, l = this.sounds.length; i < l; i++) { | |
this.sounds[i].pause(); | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment