-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsoundLibrary.min.js
1 lines (1 loc) · 960 Bytes
/
soundLibrary.min.js
1
!function(i){var r=function(i){document.createElement("audio").canPlayType&&(this.sounds=i,this.library={},this.init())};r.prototype={init:function(){this.sounds.forEach(function(i){this.library[i.name]={},this.library[i.name].source=this.determineBestSource(i.sources),this.library[i.name].audio=new Audio(i.preload?this.library[i.name].source.file:"")},this)},determineBestSource:function(i){for(var r,a,e=new Audio,t=0;t<i.length;t++){if(r=e.canPlayType(i[t].format),"probably"===r){a=i[t];break}"maybe"===r&&(a=i[t])}return a},isLoaded:function(i){return this.library[i].audio.readyState>2?!0:!1},isPlayable:function(i){var r=this.library[i]||!1;return!r||r&&!r.source?!1:r.audio.canPlayType(r.source.format)||"unknown"},play:function(i){return this.isPlayable(i)?(this.library[i].audio.currentSrc?this.library[i].audio.currentTime=0:this.library[i].audio.src=this.library[i].source.file,this.library[i].audio.play(),void 0):!1}},i.SoundLibrary=r}(window);