mirror of
https://github.com/sbrl/soundbox.git
synced 2018-01-10 21:33:43 +00:00
1 line
657 B
JavaScript
1 line
657 B
JavaScript
function SoundBox(){this.sounds={},this.sound_callbacks={},this.load=function(s,n){this.sounds[s]=new Audio(n),this.sounds[s].addEventListener("ended",function(n){n.target.currentTime=0,"function"==typeof this.sound_callbacks[s]&&(this.sound_callbacks[s](s),delete this.sound_callbacks[s])}.bind(this))},this.remove=function(s){"undefined"!=typeof this.sounds&&delete this.sounds[s],"function"==typeof this.sound_callbacks&&delete this.sound_callbacks[s]},this.play=function(s,n){return"undefined"==typeof this.sounds[s]?(console.error("Can't find sound called '"+s+"'."),!1):("function"==typeof n&&(this.sound_callbacks[s]=n),void this.sounds[s].play())}}
|