EmbyCrackedClient/web/modules/howlerjs/howler.core.js

1 line
8.2 KiB
JavaScript
Raw Permalink Normal View History

2025-06-25 11:46:04 +08:00
let HowlerGlobal=function(){this._counter=1e3,this._howls=[],this._muted=!1,this._volume=1,this.masterGain=null,this.noAudio=!1,this.autoSuspend=!0,this.ctx=null,this.bound_onAutoSuspendTimeout=this._onAutoSuspendTimeout.bind(this),this.bound_handleSuspension=this._handleSuspension.bind(this),this.bound_onCtxResume=this._onCtxResume.bind(this),this._setup()},Howler=(HowlerGlobal.prototype={_setup:function(){return this.state=this.ctx&&this.ctx.state||"suspended",this._autoSuspend(),this},_handleSuspension:function(){this.state="suspended",this._resumeAfterSuspend&&(delete this._resumeAfterSuspend,this._autoResume())},_onAutoSuspendTimeout:function(){this.autoSuspend&&(this._suspendTimer=null,this.state="suspending",this.ctx.suspend().then(this.bound_handleSuspension,this.bound_handleSuspension))},_autoSuspend:function(){if(this.autoSuspend&&this.ctx&&void 0!==this.ctx.suspend){for(let i=0;i<this._howls.length;i++)for(let j=0;j<this._howls[i]._sounds.length;j++)if(!this._howls[i]._sounds[j]._paused)return this;return this._suspendTimer&&clearTimeout(this._suspendTimer),this._suspendTimer=setTimeout(this.bound_onAutoSuspendTimeout,3e4),this}},_onCtxResume:function(){this.state="running";for(let i=0;i<this._howls.length;i++)this._howls[i]._onResume&&this._howls[i]._onResume()},_autoResume:function(){if(this.ctx&&void 0!==this.ctx.resume)return"running"===this.state&&"interrupted"!==this.ctx.state&&this._suspendTimer?(clearTimeout(this._suspendTimer),this._suspendTimer=null):"suspended"===this.state||"running"===this.state&&"interrupted"===this.ctx.state?(this.ctx.resume().then(this.bound_onCtxResume),this._suspendTimer&&(clearTimeout(this._suspendTimer),this._suspendTimer=null)):"suspending"===this.state&&(this._resumeAfterSuspend=!0),this}},new HowlerGlobal),cache={},loadSound=function(self,buffer){buffer&&!self._duration&&(self._duration=buffer.duration),0===Object.keys(self._sprite).length&&(self._sprite={__default:[0,1e3*self._duration]}),"loaded"!==self._state&&(self._state="loaded",self._loadQueue())},decodeAudioData=function(arraybuffer,self){function error(){console.log("loaderror")}function success(buffer){buffer&&0<self._sounds.length?(cache[self._src]=buffer,loadSound(self,buffer)):error()}1===Howler.ctx.decodeAudioData.length?Howler.ctx.decodeAudioData(arraybuffer).then(success).catch(error):Howler.ctx.decodeAudioData(arraybuffer,success,error)},loadBuffer=function(self){let url=self._src;if(cache[url])self._duration=cache[url].duration,loadSound(self);else{let xhr=new XMLHttpRequest;xhr.open(self._xhr.method,url,!0),xhr.withCredentials=self._xhr.withCredentials,xhr.responseType="arraybuffer",self._xhr.headers&&Object.keys(self._xhr.headers).forEach(function(key){xhr.setRequestHeader(key,self._xhr.headers[key])}),xhr.onload=function(){var code=(xhr.status+"")[0];"0"!==code&&"2"!==code&&"3"!==code?console.log("loaderror"):decodeAudioData(xhr.response,self)},xhr.onerror=function(){self.noAudio=!0,self._sounds=[],delete cache[url],self.load()};try{xhr.send()}catch(e){xhr.onerror()}}},setupAudioContext=function(){if(!Howler.noAudio){try{"undefined"!=typeof AudioContext?Howler.ctx=new AudioContext:Howler.noAudio=!0}catch(e){Howler.noAudio=!0}Howler.ctx||(Howler.noAudio=!0),Howler.noAudio||(Howler.masterGain=Howler.ctx.createGain(),Howler.masterGain.gain.setValueAtTime(Howler._muted?0:Howler._volume,Howler.ctx.currentTime),Howler.masterGain.connect(Howler.ctx.destination)),Howler._setup()}},Sound=function(howl){this._parent=howl,this.init()},Howl=(Sound.prototype={init:function(){var parent=this._parent;return this._muted=parent._muted,this._volume=parent._volume,this._paused=!0,this._ended=!0,this._sprite="__default",this._id=++Howler._counter,parent._sounds.push(this),this.create(),this},create:function(){var volume=Howler._muted||this._muted||this._parent._muted?0:this._volume;return this._node=Howler.ctx.createGain(),this._node.gain.setValueAtTime(volume,Howler.ctx.currentTime),this._node.paused=!0,this._node.connect(Howler.masterGain),this},reset:function(){var parent=this._parent;return this._muted=parent._mute