Файловый менеджер - Редактировать - /home/newsgini/news74.in/MrDino/howler-sound-manager/howler-sound-manager.js
Назад
var gdjs;(function(a){const h=new a.Logger("Audio manager"),_=["audio"],c={preload:!0,onplayerror:(u,e)=>h.error("Can't play an audio file: "+e),onloaderror:(u,e)=>h.error("Error while loading an audio file: "+e)},d=u=>u>1?1:u<0?0:u;class p{constructor(e,s,t,l){this._id=null;this._oncePlay=[];this._onPlay=[];this._howl=e,this._initialVolume=d(s),this._loop=t,this._rate=l}isLoaded(){return this._howl.state()==="loaded"}play(){if(this.isLoaded()){const e=this._howl.play(this._id===null?"__default":this._id);this._id=e,this._howl.volume(this._initialVolume,e),this._howl.loop(this._loop,e),this._howl.rate(a.HowlerSoundManager.clampRate(this._rate),e),this._onPlay.forEach(s=>{this.on("play",s),s(e)}),this._oncePlay.forEach(s=>s(e)),this._onPlay=[],this._oncePlay=[]}else this._howl.once("load",()=>this.play());return this}pause(){return this._id!==null&&this._howl.pause(this._id),this}stop(){return this._id!==null&&this._howl.stop(this._id),this}playing(){return(this._id!==null?this._howl.playing(this._id):!0)||!this.isLoaded()}paused(){return!this.playing()}stopped(){return this.paused()&&this.getSeek()===0}getRate(){return this._rate}setRate(e){return this._rate=e,this._id!==null&&(e=a.HowlerSoundManager.clampRate(e),this._howl.rate(e,this._id)),this}getLoop(){return this._loop}setLoop(e){return this._loop=e,this._id!==null&&this._howl.loop(e,this._id),this}getVolume(){return this._id===null?this._initialVolume:this._howl.volume(this._id)}setVolume(e){return this._initialVolume=d(e),this._id!==null&&this._howl.volume(this._initialVolume,this._id),this}getMute(){return this._id===null?!1:this._howl.mute(this._id)}setMute(e){return this._id!==null&&this._howl.mute(e,this._id),this}getSeek(){return this._id===null?0:this._howl.seek(this._id)}setSeek(e){return this._id!==null&&this._howl.seek(e,this._id),this}getSpatialPosition(e){return this._id===null?0:this._howl.pos(this._id)[e==="x"?0:e==="y"?1:2]}setSpatialPosition(e,s,t){return this._id!==null&&this._howl.pos(e,s,t,this._id),this}fade(e,s,t){return this._id!==null&&this._howl.fade(d(e),d(s),t,this._id),this}on(e,s){return e==="play"?this._id===null?this._onPlay.push(s):this._howl.on(e,s,this._id):this._id===null?this.once("play",()=>this.on(e,s)):this._howl.on(e,s,this._id),this}once(e,s){return e==="play"?this._id===null?this._oncePlay.push(s):this.playing()?s(this._id):this._howl.once(e,s,this._id):this._id===null?this.once("play",()=>this.once(e,s)):this._howl.once(e,s,this._id),this}off(e,s){return this._id!==null&&this._howl.off(e,s,this._id),this}}a.HowlerSound=p;class f{constructor(e){this._loadedMusics=new a.ResourceCache;this._loadedSounds=new a.ResourceCache;this._availableResources={};this._globalVolume=100;this._sounds={};this._cachedSpatialPosition={};this._musics={};this._freeSounds=[];this._freeMusics=[];this._pausedSounds=[];this._paused=!1;this._getAudioResource=e=>{const s=this._resourceLoader.getResource(e);return s&&this.getResourceKinds().includes(s.kind)?s:{file:e,kind:"audio",metadata:"",name:e}};this._resourceLoader=e,a.registerRuntimeScenePostEventsCallback(this._clearCachedSpatialPosition.bind(this));const s=this;document.addEventListener("deviceready",function(){document.addEventListener("pause",function(){s.pauseAllActiveSounds()},!1),document.addEventListener("resume",function(){s.resumeAllActiveSounds()},!1)})}pauseAllActiveSounds(){const e=this._freeSounds.concat(this._freeMusics);for(let s in this._sounds)this._sounds.hasOwnProperty(s)&&e.push(this._sounds[s]);for(let s in this._musics)this._musics.hasOwnProperty(s)&&e.push(this._musics[s]);for(let s=0;s<e.length;s++){const t=e[s];!t.paused()&&!t.stopped()&&(t.pause(),this._pausedSounds.push(t))}this._paused=!0}resumeAllActiveSounds(){try{for(let e=0;e<this._pausedSounds.length;e++){const s=this._pausedSounds[e];s.stopped()||s.play()}}catch(e){if(e.message&&typeof e.message=="string"&&e.message.startsWith("Maximum call stack size exceeded"))console.warn("An error occurred when resuming paused sounds while the game was in background:",e);else throw e}this._pausedSounds.length=0,this._paused=!1}getResourceKinds(){return _}static clampRate(e){return e>4?4:e<.5?.5:e}_getSoundUrlsFromResource(e){return[this._resourceLoader.getFullUrl(e.file)]}_getDefaultSoundUrl(e){return this._resourceLoader.getFullUrl(e.file)}_preloadAudioFile(e,s){const t=e.file;return new Promise((l,i)=>{const o=s?this._loadedMusics:this._loadedSounds;o[t]=new Howl(Object.assign({},c,{src:this._getSoundUrlsFromResource(e),onload:l,onloaderror:(r,n)=>i(n),html5:s,xhr:{withCredentials:this._resourceLoader.checkIfCredentialsRequired(t)},volume:0}))})}_storeSoundInArray(e,s){for(let t=0,l=e.length;t<l;++t)if(!e[t]||e[t].stopped())return e[t]=s,s;return e.push(s),s}createHowlerSound(e,s,t,l,i){const o=s?this._loadedMusics:this._loadedSounds,r=this._getAudioResource(e);let n=o.get(r);return n||(n=new Howl(Object.assign({src:this._getSoundUrlsFromResource(r),html5:s,xhr:{withCredentials:this._resourceLoader.checkIfCredentialsRequired(r.file)},volume:0},c)),o.set(r,n)),new a.HowlerSound(n,t,l,i)}loadAudio(e,s){const t=s?this._loadedMusics:this._loadedSounds,l=this._getAudioResource(e);t.get(l)||t.set(l,new Howl(Object.assign({src:this._getSoundUrlsFromResource(l),html5:s,xhr:{withCredentials:this._resourceLoader.checkIfCredentialsRequired(l.file)},volume:0},c)))}unloadAudio(e,s){const t=s?this._loadedMusics:this._loadedSounds,l=this._getAudioResource(e),i=t.get(l);if(!i)return;function o(r){for(let n in r)r[n]&&r[n]._howl===i&&(r[n].stop(),delete r[n])}o(this._freeMusics),o(this._freeSounds),o(Object.values(this._musics)),o(Object.values(this._sounds)),o(this._pausedSounds),i.unload(),t.delete(l)}unloadAll(){Howler.unload(),this._freeSounds.length=0,this._freeMusics.length=0,this._sounds={},this._musics={},this._pausedSounds.length=0,this._loadedMusics.clear(),this._loadedSounds.clear()}playSound(e,s,t,l){const i=this.createHowlerSound(e,!1,t/100,s,l);this._storeSoundInArray(this._freeSounds,i),i.once("play",()=>{this._paused&&(i.pause(),this._pausedSounds.push(i))}),i.play()}playSoundOnChannel(e,s,t,l,i){this._sounds[s]&&this._sounds[s].stop();const o=this.createHowlerSound(e,!1,l/100,t,i),r=this._cachedSpatialPosition[s];r&&o.once("play",()=>{o.setSpatialPosition(...r)}),this._sounds[s]=o,o.once("play",()=>{this._paused&&(o.pause(),this._pausedSounds.push(o))}),o.play()}getSoundOnChannel(e){return this._sounds[e]||null}playMusic(e,s,t,l){const i=this.createHowlerSound(e,!0,t/100,s,l);this._storeSoundInArray(this._freeMusics,i),i.once("play",()=>{this._paused&&(i.pause(),this._pausedSounds.push(i))}),i.play()}playMusicOnChannel(e,s,t,l,i){this._musics[s]&&this._musics[s].stop();const o=this.createHowlerSound(e,!0,l/100,t,i);this._musics[s]=o,o.once("play",()=>{this._paused&&(o.pause(),this._pausedSounds.push(o))}),o.play()}getMusicOnChannel(e){return this._musics[e]||null}setSoundSpatialPositionOnChannel(e,s,t,l){const i=this.getSoundOnChannel(e);i&&!i.paused()?i.setSpatialPosition(s,t,l):this._cachedSpatialPosition[e]=[s,t,l]}_clearCachedSpatialPosition(){this._cachedSpatialPosition={}}setGlobalVolume(e){this._globalVolume=e,this._globalVolume>100&&(this._globalVolume=100),this._globalVolume<0&&(this._globalVolume=0),Howler.volume(this._globalVolume/100)}getGlobalVolume(){return this._globalVolume}clearAll(){Howler.stop(),this._freeSounds.length=0,this._freeMusics.length=0,this._sounds={},this._musics={},this._pausedSounds.length=0}async processResource(e){}async loadResource(e){const s=this._resourceLoader.getResource(e);if(!s){h.warn('Unable to find audio for resource "'+e+'".');return}if(s.file){if(this._availableResources[s.name])return;this._availableResources[s.name]=s}if(s.preloadAsMusic)try{await this._preloadAudioFile(s,!0)}catch(t){h.warn("There was an error while preloading an audio file: "+t)}if(s.preloadAsSound)try{await this._preloadAudioFile(s,!1)}catch(t){h.warn("There was an error while preloading an audio file: "+t)}else if(s.preloadInCache||!s.preloadAsMusic)try{const t=s.file;await new Promise((l,i)=>{const o=new XMLHttpRequest;o.withCredentials=this._resourceLoader.checkIfCredentialsRequired(t),o.addEventListener("load",l),o.addEventListener("error",r=>i("XHR error: "+t)),o.addEventListener("abort",r=>i("XHR abort: "+t)),o.open("GET",this._getDefaultSoundUrl(s)),o.send()})}catch(t){h.warn("There was an error while preloading an audio file: "+t)}}dispose(){this.unloadAll()}unloadResourcesList(e){e.forEach(s=>{this._loadedMusics.get(s)&&this.unloadAudio(s.name,!0),this._loadedSounds.get(s)&&this.unloadAudio(s.name,!1)})}}a.HowlerSoundManager=f,a.SoundManager=f})(gdjs||(gdjs={})); //# sourceMappingURL=howler-sound-manager.js.map
| ver. 1.6 |
Github
|
.
| PHP 8.1.31 | Генерация страницы: 0.06 |
proxy
|
phpinfo
|
Настройка