mirror of
https://github.com/sbrl/soundbox.git
synced 2018-01-10 21:33:43 +00:00
Bugfixed, tested, and added example
This commit is contained in:
parent
565c587b34
commit
6777e14664
1 changed files with 5 additions and 4 deletions
|
@ -1,16 +1,17 @@
|
|||
function SoundBox() {
|
||||
this.sounds = {};
|
||||
this.sound_callbacks = {};
|
||||
this.add_sound = function(sound_name, path) {
|
||||
this.load = function(sound_name, path) {
|
||||
this.sounds[sound_name] = new Audio(path);
|
||||
// reset the sound ready for the next playing
|
||||
this.sounds[sound_name].addEventListener("ended", function(event) {
|
||||
this.sounds[sound_name].addEventListener("ended", (function(event) {
|
||||
event.target.currentTime = 0;
|
||||
if(typeof this.sound_callbacks[sound_name] == "function")
|
||||
{
|
||||
this.sound_callbacks[sound_name](sound_name);
|
||||
delete this.sound_callbacks[sound_name];
|
||||
}
|
||||
});
|
||||
}).bind(this));
|
||||
};
|
||||
|
||||
this.remove = function(sound_name) {
|
||||
|
@ -30,6 +31,6 @@ function SoundBox() {
|
|||
if(typeof callback == "function")
|
||||
this.sound_callbacks[sound_name] = callback;
|
||||
|
||||
this..sounds[sound_name].play();
|
||||
this.sounds[sound_name].play();
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue