1
0
Fork 0

Really fix it this time! :P

This commit is contained in:
Starbeamrainbowlabs 2017-07-31 19:16:47 +01:00
parent 3f94b0e65a
commit 52c0ce673c
3 changed files with 3 additions and 5 deletions

View File

@ -3,8 +3,8 @@ A super simple JS library for playing sound effects and other audio.
Now with button mashing support!
* Current size: `1.2kb`
* Current minified size: `0.78kb`
* Current size: `1.4kb`
* Current minified size: `0.74kb`
## To use:

View File

@ -37,12 +37,10 @@ function SoundBox() {
soundInstance.play();
if(typeof callback == "function") {
console.log("Adding callback");
soundInstance.addEventListener("ended", callback);
return true;
}
else {
console.log("Returning promise");
return new Promise((resolve, reject) => soundInstance.addEventListener("ended", resolve));
}
};

2
soundbox.min.js vendored
View File

@ -1 +1 @@
function SoundBox(){this.sounds={},this.load=function(a,b,c){return this.sounds[a]=new Audio(b),"function"==typeof c?void this.sounds[a].addEventListener("canplaythrough",c):new Promise(d=>this.sounds[a].addEventListener("canplaythrough",d),this.sounds[a].addEventListener("error",reject))},this.remove=function(a){"undefined"!=typeof this.sounds&&delete this.sounds[a],"function"==typeof this.sound_callbacks&&delete this.sound_callbacks[a]},this.play=function(a,b){if("undefined"==typeof this.sounds[a])return console.error("Can't find sound called '"+a+"'."),!1;var c=this.sounds[a].cloneNode(!0);return c.play(),"function"==typeof b?(console.log("Adding callback"),c.addEventListener("ended",b),!0):(console.log("Returning promise"),new Promise(d=>c.addEventListener("ended",d)))}}SoundBox.version="0.2";
function SoundBox(){this.sounds={},this.load=function(a,b,c){return this.sounds[a]=new Audio(b),"function"==typeof c?void this.sounds[a].addEventListener("canplaythrough",c):new Promise((d,e)=>{this.sounds[a].addEventListener("canplaythrough",d),this.sounds[a].addEventListener("error",e)})},this.remove=function(a){"undefined"!=typeof this.sounds&&delete this.sounds[a],"function"==typeof this.sound_callbacks&&delete this.sound_callbacks[a]},this.play=function(a,b){if("undefined"==typeof this.sounds[a])return console.error("Can't find sound called '"+a+"'."),!1;var c=this.sounds[a].cloneNode(!0);return c.play(),"function"==typeof b?(c.addEventListener("ended",b),!0):new Promise(d=>c.addEventListener("ended",d))}}SoundBox.version="0.2";