1
0
Fork 0
soundbox/soundbox.min.js

2 lines
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())}}