Comparing version 1.0.10-beta.10 to 1.0.10-beta.11
@@ -1,6 +0,5 @@ | ||
var K=Object.defineProperty;var V=Object.getOwnPropertySymbols;var ne=Object.prototype.hasOwnProperty,le=Object.prototype.propertyIsEnumerable;var I=(s,e,t)=>e in s?K(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,R=(s,e)=>{for(var t in e||(e={}))ne.call(e,t)&&I(s,t,e[t]);if(V)for(var t of V(e))le.call(e,t)&&I(s,t,e[t]);return s};var n=(s,e)=>K(s,"name",{value:e,configurable:!0});var u=(s,e,t)=>I(s,typeof e!="symbol"?e+"":e,t);var p=(s,e,t)=>new Promise((a,i)=>{var r=A=>{try{h(t.next(A));}catch(m){i(m);}},c=A=>{try{h(t.throw(A));}catch(m){i(m);}},h=A=>A.done?a(A.value):Promise.resolve(A.value).then(r,c);h((t=t.apply(s,e)).next());});var Y=[{frequency:31,type:"lowshelf",gain:0},{frequency:63,type:"peaking",gain:0},{frequency:125,type:"peaking",gain:0},{frequency:250,type:"peaking",gain:0},{frequency:500,type:"peaking",gain:0},{frequency:1e3,type:"peaking",gain:0},{frequency:2e3,type:"peaking",gain:0},{frequency:4e3,type:"peaking",gain:0},{frequency:8e3,type:"peaking",gain:0},{frequency:16e3,type:"highshelf",gain:0}],F=[{name:"Default",id:"default",default:!0,gains:[0,0,0,0,0,0,0,0,0,0]},{name:"Club",id:"club",default:!0,gains:[0,0,4.8,3.36,3.36,3.36,1.92,0,0,0]},{name:"Live",id:"live",default:!0,gains:[-2.88,0,2.4,3.36,3.36,3.36,2.4,1.44,1.44,1.44]},{name:"Party",id:"Party",default:!0,gains:[4.32,4.32,0,0,0,0,0,0,4.32,4.32]},{name:"Pop",id:"pop",default:!0,gains:[.96,2.88,4.32,4.8,3.36,0,-1.44,-1.44,.96,.96]},{name:"Soft",id:"soft",default:!0,gains:[2.88,.96,0,-1.44,0,2.4,4.8,5.76,6.72,7.2]},{name:"Ska",id:"ska",default:!0,gains:[-1.44,-2.88,-2.4,0,2.4,3.36,5.28,5.76,6.72,5.76]},{name:"Reggae",id:"reggae",default:!0,gains:[0,0,0,-3.36,0,3.84,3.84,0,0,0]},{name:"Rock",id:"rock",default:!0,gains:[4.8,2.88,-3.36,-4.8,-1.92,2.4,5.28,6.72,6.72,6.72]},{name:"Dance",id:"dance",default:!0,gains:[5.76,4.32,1.44,0,0,-3.36,-4.32,-4.32,0,0]},{name:"Techno",id:"techno",default:!0,gains:[4.8,3.36,0,-3.36,-2.88,0,4.8,5.76,5.76,5.28]},{name:"Headphones",id:"headphones",default:!0,gains:[2.88,6.72,3.36,-1.92,-1.44,.96,2.88,5.76,7.68,8.64]},{name:"Soft rock",id:"soft_rock",default:!0,gains:[2.4,2.4,1.44,0,-2.4,-3.36,-1.92,0,1.44,5.28]},{name:"Classical",id:"classical",default:!0,gains:[0,0,0,0,0,0,-4.32,-4.32,-4.32,-5.76]},{name:"Large Hall",id:"large_hall",default:!0,gains:[6.24,6.24,3.36,3.36,0,-2.88,-2.88,-2.88,0,0]},{name:"Full Bass",id:"full_base",default:!0,gains:[4.8,5.76,5.76,3.36,.96,-2.4,-4.8,-6.24,-6.72,-6.72]},{name:"Full Treble",id:"full_treble",default:!0,gains:[-5.76,-5.76,-5.76,-2.4,1.44,6.72,9.6,9.6,9.6,10.08]},{name:"Laptop Speakers",id:"laptop_speakers",default:!0,gains:[2.88,6.72,3.36,-1.92,-1.44,.96,2.88,5.76,7.68,8.64]},{name:"Full Bass & Treble",id:"bass_treble",default:!0,gains:[4.32,3.36,0,-4.32,-2.88,.96,4.8,6.72,7.2,7.2]}];var k=Object.freeze({REACT:"REACT",VANILLA:"VANILLA",DEVELOPMENT:"development"}),l=Object.freeze({BUFFERING:"buffering",PLAYING:"playing",PAUSED:"paused",READY:"ready",IDLE:"idle",ENDED:"ended",STALLED:"stalled",ERROR:"error",TRACK_CHANGE:"trackchanged",DURATION_CHANGE:"durationchanged",QUEUE_ENDED:"queueended"}),b=Object.freeze({MEDIA_ERR_ABORTED:"The user canceled the audio.",MEDIA_ERR_DECODE:"An error occurred while decoding the audio.",MEDIA_ERR_NETWORK:"A network error occurred while fetching the audio.",MEDIA_ERR_SRC_NOT_SUPPORTED:"The audio is missing or is in a format not supported by your browser.",DEFAULT:"An unknown error occurred."}),Q={HLS:"https://cdnjs.cloudflare.com/ajax/libs/hls.js/1.5.11/hls.min.js",CAST:"https://www.gstatic.com/cv/js/sender/v1/cast_sender.js?loadCastFramework=1"};var E,ue=(E=class{static validateEventName(e){if(!e||typeof e!="string")throw new Error("Invalid event name")}static notify(e,t,a="audiox_notifier_default"){this.validateEventName(e);let i=E.listeners[e];i&&t!==null&&(console.log(`NOTIFYING TO EVENT : ${e} - CALLER : ${a}`),E.notifierState[e]=R(R({},E.notifierState[e]||{}),t),i.forEach(r=>{r(E.notifierState[e]);}));}static listen(e,t,a={}){if(this.validateEventName(e),typeof t!="function")throw new Error("Callback must be a function");return E.listeners[e]?E.listeners[e].add(t):(E.notifierState[e]=a,E.listeners[e]=new Set([t])),()=>{let i=E.listeners[e];if(!i){console.log(`EVENT NOT FOUND : ${e}`);return}console.log(`REMOVING EVENT LISTENER FOR EVENT : ${e}`),i.delete(t),i.size===0&&delete E.listeners[e];}}static multiListen(e,t,a={}){if(this.validateEventName(e),!Array.isArray(t)||t.length===0)throw new Error("Callbacks must be a non-empty array of functions");let i=t.map(r=>E.listen(e,r,a));return ()=>{i.forEach(r=>r());}}static getLatestState(e){return this.validateEventName(e),E.notifierState[e]}},n(E,"ChangeNotifier"),u(E,"listeners",{}),u(E,"notifierState",{}),E),f=ue;var _=n(s=>s&&Array.isArray(s)&&s.length,"isValidArray"),X=n(s=>s instanceof Function&&typeof s=="function","isValidFunction");var z={},j=n(s=>{let e="",t=s.error;switch(t==null?void 0:t.code){case MediaError.MEDIA_ERR_ABORTED:e+=b.MEDIA_ERR_ABORTED;break;case MediaError.MEDIA_ERR_NETWORK:e+=b.MEDIA_ERR_NETWORK;break;case MediaError.MEDIA_ERR_DECODE:e+=b.MEDIA_ERR_DECODE;break;case MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED:e+=b.MEDIA_ERR_SRC_NOT_SUPPORTED;break;default:e+=b.DEFAULT;break}return e},"getReadableErrorMessage"),$=n(s=>{var m;let{title:e,album:t,artist:a,artwork:i}=s,r=i?(m=i[0])==null?void 0:m.src:"",h=["96x96","128x128","192x192","256x256","384x384","512x512"].map(P=>({src:r,sizes:P,type:"image/png"}));return {title:e,album:t,artist:a,artwork:h}},"metaDataCreator"),x=0,L=n((s,e)=>{let t=new Set;for(let r=0;r<s.played.length;r++){let c=s.played.start(r),A=s.played.end(r)-c;t.add(A);}let i=[...t].reduce((r,c)=>r+c,0);x=["ENDED","TRACK_CHANGE","PAUSE"].includes(e)?i:x,f.notify("AUDIO_STATE",{currentTrackPlayTime:i,previousTrackPlayTime:x});},"calculateActualPlayedLength"),W=n((s,e,t)=>new Promise((a,i)=>{if(window instanceof Window&&window.document)if(z[t])e(),a();else {z[t]=!0;let r=document.createElement("script");r.type="text/javascript",r.src=s,r.async=!0,r.onload=()=>{e(),a();},document.head.appendChild(r);}else i(`Window not ready unable to initialize ${t}`);}),"loadScript"),J=n(()=>{let s=new T,e=!1,t=n(a=>{if(a.playbackState==="ended"&&!e){let i=s.getQueue();e=!0,i&&_(i)&&e&&s.playNext();}a.playbackState!=="ended"&&(e=!1);},"audioStateListener");f.listen("AUDIO_STATE",t);},"handleQueuePlayback"),y=n(s=>{let{buffered:e}=s,t=0;for(let a=0;a<e.length;a++)t+=e.end(a)-e.start(a);return t},"getBufferedDuration"),Z=n(s=>{let e=[...s];for(let t=e.length-1;t>0;t--){let a=Math.floor(Math.random()*t);[e[t],e[a]]=[e[a],e[t]];}return e},"shuffle"),N=n((s,e)=>{if(s===null&&e===null)return !0;if(s===null||e===null||typeof s!=typeof e)return !1;if(typeof s!="object")return s===e;if(Array.isArray(s)&&Array.isArray(e))return s.length!==e.length?!1:s.every((i,r)=>N(i,e[r]));let t=Object.keys(s),a=Object.keys(e);return t.length!==a.length?!1:t.every(i=>a.includes(i)?N(s[i],e[i]):!1)},"diffChecker");var g,H=(g=class{constructor(){u(this,"audioCtx");u(this,"audioCtxStatus");u(this,"eqFilterBands");u(this,"bassBoostFilter");if(g._instance)return console.warn("Instantiation failed: cannot create multiple instances of Equalizer. Returning existing instance."),g._instance;this.initializeAudioContext(),g._instance=this;}initializeAudioContext(){let e={latencyHint:"playback",sampleRate:44100};typeof AudioContext!="undefined"?this.audioCtx=new AudioContext(e):typeof window.webkitAudioContext!="undefined"?this.audioCtx=new window.webkitAudioContext(e):console.error("Web Audio API is not supported in this browser."),this.audioCtxStatus="ACTIVE",this.init(),this.audioCtx.state==="suspended"&&this.addResumeListener();}addResumeListener(){let e=n(()=>{this.audioCtx.resume(),setTimeout(()=>{this.audioCtx.state==="running"&&document.body.removeEventListener("click",e,!1);},0);},"resume");document.body.addEventListener("click",e,!1);}init(){try{let e=T.getAudioInstance(),t=this.audioCtx.createMediaElementSource(e),a=Y.map(r=>{let c=this.audioCtx.createBiquadFilter();return c.type=r.type,c.frequency.value=r.frequency,c.gain.value=r.gain,c.Q.value=1,c}),i=this.audioCtx.createGain();i.gain.value=1,this.bassBoostFilter=this.audioCtx.createBiquadFilter(),this.bassBoostFilter.type="lowshelf",this.bassBoostFilter.frequency.value=80,this.bassBoostFilter.gain.value=0,t.connect(a[0]);for(let r=0;r<a.length-1;r++)a[r].connect(a[r+1]);a[a.length-1].connect(this.bassBoostFilter),this.bassBoostFilter.connect(i),i.connect(this.audioCtx.destination),this.audioCtxStatus="ACTIVE",this.eqFilterBands=a;}catch(e){console.error("Equalizer initialization failed:",e),this.audioCtxStatus="FAILED";}}setPreset(e){let t=F.find(i=>i.id===e);if(!t){console.error("Preset not found:",e);return}if(!this.eqFilterBands||this.eqFilterBands.length!==t.gains.length){console.error("Invalid data provided.");return}let a=this.audioCtx.currentTime;this.eqFilterBands.forEach((i,r)=>{let c=t.gains[r];i.gain.linearRampToValueAtTime(c,a+.015);});}static getPresets(){return F}status(){return this.audioCtx.state==="suspended"&&this.audioCtx.resume(),this.audioCtxStatus}setCustomEQ(e){if(_(e)){let t=this.audioCtx.currentTime;this.eqFilterBands.forEach((a,i)=>{a.gain.linearRampToValueAtTime(e[i],t+.015);});}else console.error("Invalid array of gains provided.");}setBassBoost(e,t=6){let a=this.audioCtx.currentTime;e?this.bassBoostFilter.gain.linearRampToValueAtTime(t,a+.015):this.bassBoostFilter.gain.linearRampToValueAtTime(0,a+.015);}},n(g,"Equalizer"),u(g,"_instance"),g);var ee={ERROR:n((s,e)=>{let t=e.type,a=e.details,i=e.fatal;console.log("STATUS",s.type),f.notify("AUDIO_STATE",{playbackState:l.ERROR,error:{type:t,isFatal:i,detail:a}},`audiox_baseEvents_state_${s.type}`);},"ERROR"),FRAG_CHANGED:n(()=>{console.log("FRAG_CHANGED");},"FRAG_CHANGED")};var w=Object.freeze({ABORT:"abort",TIME_UPDATE:"timeupdate",CAN_PLAY:"canplay",CAN_PLAY_THROUGH:"canplaythrough",DURATION_CHANGE:"durationchange",ENDED:"ended",EMPTIED:"emptied",PLAYING:"playing",WAITING:"waiting",SEEKING:"seeking",SEEKED:"seeked",LOADED_META_DATA:"loadedmetadata",LOADED_DATA:"loadeddata",PLAY:"play",PAUSE:"pause",RATE_CHANGE:"ratechange",VOLUME_CHANGE:"volumechange",SUSPEND:"suspend",STALLED:"stalled",PROGRESS:"progress",LOAD_START:"loadstart",ERROR:"error",TRACK_CHANGE:"trackchange",QUEUE_ENDED:"queueended"}),te={MEDIA_ATTACHING:"hlsMediaAttaching",MEDIA_ATTACHED:"hlsMediaAttached",MEDIA_DETACHING:"hlsMediaDetaching",MEDIA_DETACHED:"hlsMediaDetached",BUFFER_RESET:"hlsBufferReset",BUFFER_CODECS:"hlsBufferCodecs",BUFFER_CREATED:"hlsBufferCreated",BUFFER_APPENDING:"hlsBufferAppending",BUFFER_APPENDED:"hlsBufferAppended",BUFFER_EOS:"hlsBufferEos",BUFFER_FLUSHING:"hlsBufferFlushing",BUFFER_FLUSHED:"hlsBufferFlushed",MANIFEST_LOADING:"hlsManifestLoading",MANIFEST_LOADED:"hlsManifestLoaded",MANIFEST_PARSED:"hlsManifestParsed",LEVEL_SWITCHING:"hlsLevelSwitching",LEVEL_SWITCHED:"hlsLevelSwitched",LEVEL_LOADING:"hlsLevelLoading",LEVEL_LOADED:"hlsLevelLoaded",LEVEL_UPDATED:"hlsLevelUpdated",LEVEL_PTS_UPDATED:"hlsLevelPtsUpdated",LEVELS_UPDATED:"hlsLevelsUpdated",AUDIO_TRACKS_UPDATED:"hlsAudioTracksUpdated",AUDIO_TRACK_SWITCHING:"hlsAudioTrackSwitching",AUDIO_TRACK_SWITCHED:"hlsAudioTrackSwitched",AUDIO_TRACK_LOADING:"hlsAudioTrackLoading",AUDIO_TRACK_LOADED:"hlsAudioTrackLoaded",SUBTITLE_TRACKS_UPDATED:"hlsSubtitleTracksUpdated",SUBTITLE_TRACKS_CLEARED:"hlsSubtitleTracksCleared",SUBTITLE_TRACK_SWITCH:"hlsSubtitleTrackSwitch",SUBTITLE_TRACK_LOADING:"hlsSubtitleTrackLoading",SUBTITLE_TRACK_LOADED:"hlsSubtitleTrackLoaded",SUBTITLE_FRAG_PROCESSED:"hlsSubtitleFragProcessed",CUES_PARSED:"hlsCuesParsed",NON_NATIVE_TEXT_TRACKS_FOUND:"hlsNonNativeTextTracksFound",INIT_PTS_FOUND:"hlsInitPtsFound",FRAG_LOADING:"hlsFragLoading",FRAG_LOAD_EMERGENCY_ABORTED:"hlsFragLoadEmergencyAborted",FRAG_LOADED:"hlsFragLoaded",FRAG_DECRYPTED:"hlsFragDecrypted",FRAG_PARSING_INIT_SEGMENT:"hlsFragParsingInitSegment",FRAG_PARSING_USERDATA:"hlsFragParsingUserdata",FRAG_PARSING_METADATA:"hlsFragParsingMetadata",FRAG_PARSED:"hlsFragParsed",FRAG_BUFFERED:"hlsFragBuffered",FRAG_CHANGED:"hlsFragChanged",FPS_DROP:"hlsFpsDrop",FPS_DROP_LEVEL_CAPPING:"hlsFpsDropLevelCapping",ERROR:"hlsError",DESTROYING:"hlsDestroying",KEY_LOADING:"hlsKeyLoading",KEY_LOADED:"hlsKeyLoaded",LIVE_BACK_BUFFER_REACHED:"hlsLiveBackBufferReached",BACK_BUFFER_REACHED:"hlsBackBufferReached"};var B=n((s,e=!1)=>{let t=T.getAudioInstance();_(Object.keys(s))&&Object.keys(s).forEach(a=>{let i=a;t==null||t.addEventListener(w[i],r=>{if(a&&s[i]){let c=s[i];typeof c=="function"&&c(r,t,e);}});});},"attachEventListeners");var se=n((s,e=!1)=>{let a=new O().getHlsInstance();_(Object.keys(s))&&Object.keys(s).forEach(i=>{let r=i;a.on(te[r],(c,h)=>{if(r&&s[r]){let A=s[r];typeof A=="function"&&A(c,h,a,e);}});});},"attachHlsEventsListeners");var C,S,ce=(S=class{constructor(){u(this,"HlsClass");if(S._instance)return console.warn("Instantiation failed: cannot create multiple instance of HLS returning existing instance"),S._instance;S._instance=this;}load(){return p(this,null,function*(){return yield W(Q.HLS,()=>{console.log("HLS Loaded");},"hls").then(()=>{this.HlsClass=window.Hls,window.Hls=void 0;}).catch(e=>{console.log(e);}),this.HlsClass})}init(){return p(this,arguments,function*(e={},t){let a=yield this.load();a.isSupported()&&(C=new a(e),se(ee,t));})}addHlsMedia(e){let t=this.HlsClass,a=T.getAudioInstance();C.loadSource(e.source),C.attachMedia(a),C.on(t.Events.MEDIA_ATTACHED,function(){console.log("hls media attached");});}getHlsInstance(){return C}},n(S,"HlsAdapter"),u(S,"_instance"),S),O=ce;var ae=Object.freeze({1:"MEDIA_ERR_ABORTED",3:"MEDIA_ERR_DECODE",2:"MEDIA_ERR_NETWORK",4:"MEDIA_ERR_SRC_NOT_SUPPORTED"});var d=f,ie={LOAD_START:n((s,e)=>{console.log("STATUS",s.type);let t=y(e);d.notify("AUDIO_STATE",{playbackState:l.BUFFERING,duration:e==null?void 0:e.duration,error:{code:null,message:"",readable:""},bufferedDuration:t},`audiox_baseEvents_state_${s.type}`);},"LOAD_START"),DURATION_CHANGE:n((s,e)=>{console.log("STATUS",s.type);let t=d.getLatestState("AUDIO_X_STATE"),a=y(e);d.notify("AUDIO_STATE",{playbackState:t.playbackState==="playing"?l.PLAYING:l.DURATION_CHANGE,duration:e==null?void 0:e.duration,error:{code:null,message:"",readable:""},bufferedDuration:a},`audiox_baseEvents_state_${s.type}`);},"DURATION_CHANGE"),LOADED_META_DATA:n((s,e)=>{console.log("STATUS",s.type);let t=y(e);d.notify("AUDIO_STATE",{playbackState:l.BUFFERING,duration:e==null?void 0:e.duration,error:{code:null,message:"",readable:""},bufferedDuration:t},`audiox_baseEvents_state_${s.type}`);},"LOADED_META_DATA"),LOADED_DATA:n((s,e)=>{console.log("STATUS",s.type);let t=y(e);d.notify("AUDIO_STATE",{playbackState:l.BUFFERING,duration:e==null?void 0:e.duration,error:{code:null,message:"",readable:""},bufferedDuration:t},`audiox_baseEvents_state_${s.type}`);},"LOADED_DATA"),CAN_PLAY:n((s,e)=>{console.log("STATUS",s.type);let t=d.getLatestState("AUDIO_X_STATE"),a=y(e);d.notify("AUDIO_STATE",{playbackState:t.playbackState==="paused"?l.PAUSED:l.READY,error:{code:null,message:"",readable:""},bufferedDuration:a},`audiox_baseEvents_state_${s.type}`);},"CAN_PLAY"),CAN_PLAY_THROUGH:n((s,e)=>{console.log("STATUS",s.type);let t=d.getLatestState("AUDIO_X_STATE"),a=e.paused,i=y(e);d.notify("AUDIO_STATE",{playbackState:a?l.PAUSED:t.playbackState==="playing"?l.PLAYING:l.READY,error:{code:null,message:"",readable:""},bufferedDuration:i},`audiox_baseEvents_state_${s.type}`);},"CAN_PLAY_THROUGH"),PLAY:n((s,e)=>{console.log("STATUS",s.type),d.notify("AUDIO_STATE",{playbackState:l.PLAYING,progress:e==null?void 0:e.currentTime,error:{code:null,message:"",readable:""}},`audiox_baseEvents_state_${s.type}`);},"PLAY"),PLAYING:n((s,e)=>{console.log("STATUS",s.type),d.notify("AUDIO_STATE",{playbackState:l.PLAYING,progress:e==null?void 0:e.currentTime,error:{code:null,message:"",readable:""}},`audiox_baseEvents_state_${s.type}`);},"PLAYING"),PAUSE:n((s,e,t)=>{console.log("STATUS",s.type),d.notify("AUDIO_STATE",{playbackState:l.PAUSED,progress:e==null?void 0:e.currentTime,error:{code:null,message:"",readable:""}},`audiox_baseEvents_state_${s.type}`),t&&L(e,"PAUSE");},"PAUSE"),ENDED:n((s,e,t)=>{console.log("STATUS",s.type),d.notify("AUDIO_STATE",{playbackState:l.ENDED,progress:e==null?void 0:e.currentTime,error:{code:null,message:"",readable:""}},`audiox_baseEvents_state_${s.type}`),t&&L(e,"ENDED");},"ENDED"),ERROR:n((s,e)=>{var i;console.log("STATUS",s.type);let t=(i=e.error)==null?void 0:i.code,a=j(e);d.notify("AUDIO_STATE",{playbackState:l.ERROR,error:{code:t,message:ae[t],readable:a}},`audiox_baseEvents_state_${s.type}`);},"ERROR"),TIME_UPDATE:n((s,e)=>{console.log("STATUS",s.type);let t=d.getLatestState("AUDIO_X_STATE"),a=y(e);d.notify("AUDIO_STATE",{playbackState:e.paused?t==null?void 0:t.playbackState:l.PLAYING,progress:e==null?void 0:e.currentTime,error:{code:null,message:"",readable:""},bufferedDuration:a},`audiox_baseEvents_state_${s.type}`);},"TIME_UPDATE"),WAITING:n((s,e)=>{console.log("STATUS",s.type),d.notify("AUDIO_STATE",{playbackState:l.BUFFERING,progress:e==null?void 0:e.currentTime,error:{code:null,message:"",readable:""}},`audiox_baseEvents_state_${s.type}`);},"WAITING"),VOLUME_CHANGE:n(s=>{console.log("STATUS",s.type),d.notify("AUDIO_STATE",{},"audiox_baseEvents_state");},"VOLUME_CHANGE"),SEEKED:n((s,e)=>{let t=d.getLatestState("AUDIO_X_STATE"),a=y(e);d.notify("AUDIO_STATE",{playbackState:t.playbackState==="paused"?"paused":t.playbackState,progress:e==null?void 0:e.currentTime,error:{code:null,message:"",readable:""},bufferedDuration:a},`audiox_baseEvents_state_${s.type}`);},"SEEKED")};var re=n(s=>{"mediaSession"in navigator&&(navigator.mediaSession.metadata=new MediaMetadata($(s)));},"updateMetaData"),q=n(()=>{let s=new T;"mediaSession"in navigator&&(navigator.mediaSession.setActionHandler("play",()=>{T.getAudioInstance().play();}),navigator.mediaSession.setActionHandler("pause",()=>{T.getAudioInstance().pause();}),s.getQueue().length&&(navigator.mediaSession.setActionHandler("previoustrack",()=>{s.playPrevious();}),navigator.mediaSession.setActionHandler("nexttrack",()=>{s.playNext();})));},"attachMediaSessionHandlers");var G={HAVE_NOTHING:0,HAVE_METADATA:1,HAVE_CURRENT_DATA:2,HAVE_FUTURE_DATA:3,HAVE_ENOUGH_DATA:4},v={playbackState:l.IDLE,duration:0,bufferedDuration:0,progress:0,volume:50,playbackRate:1,error:{code:null,message:"",readable:""},currentTrack:{},currentTrackPlayTime:0,previousTrackPlayTime:0};f.listen("AUDIO_STATE",s=>{let e=f.getLatestState("AUDIO_X_STATE");N(e,s)||f.notify("AUDIO_X_STATE",R(R({},v),s));},v);var o,U=f,D,T=(D=class{constructor(){u(this,"_audio");u(this,"isPlayLogEnabled");u(this,"_queue");u(this,"_currentQueueIndex",0);u(this,"_fetchFn");u(this,"eqStatus","IDEAL");u(this,"isEqEnabled",!1);u(this,"eqInstance");u(this,"showNotificationsActions",!1);var e;if(D._instance)return console.warn("Instantiation failed: cannot create multiple instance of AudioX returning existing instance"),D._instance;if(process.env.NODE_ENV!==((e=k)==null?void 0:e.DEVELOPMENT)&&o)throw new Error("Cannot create multiple audio instance");D._instance=this,this._audio=new Audio,o=this._audio;}init(e){return p(this,null,function*(){var M;let{preloadStrategy:t="auto",autoPlay:a=!1,useDefaultEventListeners:i=!0,customEventListeners:r=null,showNotificationActions:c=!1,enablePlayLog:h=!1,enableHls:A=!1,enableEQ:m=!1,crossOrigin:P="anonymous",hlsConfig:oe={}}=e;(M=this._audio)==null||M.setAttribute("id","audio_x_instance"),this._audio.preload=t,this._audio.autoplay=a,this._audio.crossOrigin=P,this.isPlayLogEnabled=h,this.isEqEnabled=m,r!==null?(i&&console.warn(`useDefaultEventListeners is set to true at init, are you trying to use the default event listeners? | ||
set customEventListeners to null to use default event listeners`),B(r,!1)):B(ie,h),c&&(this.showNotificationsActions=!0,q()),A&&new O().init(oe,h);})}addMedia(e){return p(this,null,function*(){if(!e)return;let t=this.getQueue();if(_(t)){let i=t.findIndex(r=>e.id===r.id);i>-1&&(this._currentQueueIndex=i);}let a=e.source.includes(".m3u8")?"HLS":"DEFAULT";if(this.isPlayLogEnabled&&L(o,"TRACK_CHANGE"),a==="HLS"){let i=new O,r=i.getHlsInstance();r?(r.detachMedia(),i.addHlsMedia(e)):(console.warn("The source provided seems to be a HLS stream but, hls playback is not enabled. Please have a look at init method of AudioX"),yield this.reset());}else o.src=e.source;U.notify("AUDIO_STATE",{playbackState:l.TRACK_CHANGE,currentTrackPlayTime:0,currentTrack:e}),re(e),o.load();})}attachEq(){if(this.eqStatus==="IDEAL")try{let e=new H;this.eqStatus=e.status(),this.eqInstance=e;}catch(e){console.log("failed to enable equalizer");}}play(){return p(this,null,function*(){let e=o.src!=="";o!=null&&o.paused&&o.HAVE_ENOUGH_DATA===G.HAVE_ENOUGH_DATA&&e&&(yield o.play().then(()=>{console.log("PLAYING");}).catch(()=>{console.warn("cancelling current audio playback, track changed");})),this.isEqEnabled&&this.attachEq();})}addMediaAndPlay(e,t){return p(this,null,function*(){let a=e||(this._queue.length>0?this._queue[0]:void 0);t&&X(t)&&a&&(this._fetchFn=t,yield t(a));try{a?this.addMedia(a).then(()=>{o.HAVE_ENOUGH_DATA===G.HAVE_ENOUGH_DATA&&setTimeout(()=>p(this,null,function*(){yield this.play(),this.isEqEnabled&&this.attachEq();}),950);}):console.error("Playback Failed, No MediaTrack Provided");}catch(i){console.error("Playback Failed");}})}pause(){o&&!(o!=null&&o.paused)&&(o==null||o.pause());}stop(){o&&!o.paused&&(o==null||o.pause(),o.currentTime=0);}reset(){return p(this,null,function*(){o&&(this.stop(),o.src="",o.srcObject=null);})}setVolume(e){let t=e/100;o&&(o.volume=t,U.notify("AUDIO_STATE",{volume:e}));}setPlaybackRate(e){o&&(o.playbackRate=e,U.notify("AUDIO_STATE",{playbackRate:e}));}mute(){o&&!o.muted&&(o.muted=!0);}seek(e){o&&(o.currentTime=e);}seekBy(e){if(o&&o.currentTime){let t=o.currentTime;o.currentTime=t+e;}}destroy(){return p(this,null,function*(){o&&(yield this.reset(),o.removeAttribute("src"),o.load());})}subscribe(e,t,a={}){return U.listen(e,t,a)}addEventListener(e,t){o.addEventListener(e,t);}getPresets(){return H.getPresets()}setPreset(e){this.isEqEnabled?this.eqInstance.setPreset(e):console.error("Equalizer not initialized, please set enableEq at init");}setCustomEQ(e){this.isEqEnabled?this.eqInstance.setCustomEQ(e):console.error("Equalizer not initialized, please set enableEq at init");}setBassBoost(e,t){this.isEqEnabled?this.eqInstance.setBassBoost(e,t):console.error("Equalizer not initialized, please set enableEq at init");}addQueue(e,t){this.clearQueue();let a=_(e)?e.slice():[];switch(t){case"DEFAULT":this._queue=a;break;case"REVERSE":this._queue=a.reverse();break;case"SHUFFLE":this._queue=Z(a);break;default:this._queue=a;break}J(),this.showNotificationsActions&&q();}playNext(){let e=this._currentQueueIndex+1;if(this._queue.length>e){let t=this._queue[e];this.addMediaAndPlay(t,this._fetchFn),this._currentQueueIndex=e;}else this.stop(),U.notify("AUDIO_STATE",{playbackState:l.QUEUE_ENDED});}playPrevious(){let e=this._currentQueueIndex-1;if(e>=0){let t=this._queue[e];this.addMediaAndPlay(t,this._fetchFn),this._currentQueueIndex=e;}else console.log("At the beginning of the queue");}clearQueue(){this._queue&&_(this._queue)&&(this._queue=[],this._currentQueueIndex=0);}addToQueue(e){this._queue&&_(this._queue)&&(Array.isArray(e)?this._queue=[...this._queue,...e]:this._queue.push(e));}removeFromQueue(e){if(this._queue&&_(this._queue)){let t=this._queue.filter(a=>a.id==e.id);this._queue=t;}}getQueue(){return this._queue&&_(this._queue)?this._queue:[]}get id(){return o==null?void 0:o.getAttribute("id")}static getAudioInstance(){return o}},n(D,"AudioX"),u(D,"_instance"),D); | ||
var K=Object.defineProperty;var V=Object.getOwnPropertySymbols;var ne=Object.prototype.hasOwnProperty,le=Object.prototype.propertyIsEnumerable;var I=(s,e,t)=>e in s?K(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,R=(s,e)=>{for(var t in e||(e={}))ne.call(e,t)&&I(s,t,e[t]);if(V)for(var t of V(e))le.call(e,t)&&I(s,t,e[t]);return s};var n=(s,e)=>K(s,"name",{value:e,configurable:!0});var c=(s,e,t)=>I(s,typeof e!="symbol"?e+"":e,t);var p=(s,e,t)=>new Promise((r,i)=>{var o=A=>{try{_(t.next(A));}catch(y){i(y);}},E=A=>{try{_(t.throw(A));}catch(y){i(y);}},_=A=>A.done?r(A.value):Promise.resolve(A.value).then(o,E);_((t=t.apply(s,e)).next());});var Y=[{frequency:31,type:"lowshelf",gain:0,q:1.2},{frequency:63,type:"peaking",gain:0,q:1.2},{frequency:125,type:"peaking",gain:0,q:1.2},{frequency:250,type:"peaking",gain:0,q:1.2},{frequency:500,type:"peaking",gain:0,q:1.2},{frequency:1e3,type:"peaking",gain:0,q:1.2},{frequency:2e3,type:"peaking",gain:0,q:1.2},{frequency:4e3,type:"peaking",gain:0,q:1.2},{frequency:8e3,type:"peaking",gain:0,q:1.2},{frequency:16e3,type:"highshelf",gain:0,q:1.2}],F=[{name:"Default",id:"default",default:!0,gains:[0,0,0,0,0,0,0,0,0,0]},{name:"Club",id:"club",default:!0,gains:[0,0,4.8,3.36,3.36,3.36,1.92,0,0,0]},{name:"Live",id:"live",default:!0,gains:[-2.88,0,2.4,3.36,3.36,3.36,2.4,1.44,1.44,1.44]},{name:"Party",id:"Party",default:!0,gains:[4.32,4.32,0,0,0,0,0,0,4.32,4.32]},{name:"Pop",id:"pop",default:!0,gains:[.96,2.88,4.32,4.8,3.36,0,-1.44,-1.44,.96,.96]},{name:"Soft",id:"soft",default:!0,gains:[2.88,.96,0,-1.44,0,2.4,4.8,5.76,6.72,7.2]},{name:"Ska",id:"ska",default:!0,gains:[-1.44,-2.88,-2.4,0,2.4,3.36,5.28,5.76,6.72,5.76]},{name:"Reggae",id:"reggae",default:!0,gains:[0,0,0,-3.36,0,3.84,3.84,0,0,0]},{name:"Rock",id:"rock",default:!0,gains:[4.8,2.88,-3.36,-4.8,-1.92,2.4,5.28,6.72,6.72,6.72]},{name:"Dance",id:"dance",default:!0,gains:[5.76,4.32,1.44,0,0,-3.36,-4.32,-4.32,0,0]},{name:"Techno",id:"techno",default:!0,gains:[4.8,3.36,0,-3.36,-2.88,0,4.8,5.76,5.76,5.28]},{name:"Headphones",id:"headphones",default:!0,gains:[2.88,6.72,3.36,-1.92,-1.44,.96,2.88,5.76,7.68,8.64]},{name:"Soft rock",id:"soft_rock",default:!0,gains:[2.4,2.4,1.44,0,-2.4,-3.36,-1.92,0,1.44,5.28]},{name:"Classical",id:"classical",default:!0,gains:[0,0,0,0,0,0,-4.32,-4.32,-4.32,-5.76]},{name:"Large Hall",id:"large_hall",default:!0,gains:[6.24,6.24,3.36,3.36,0,-2.88,-2.88,-2.88,0,0]},{name:"Full Bass",id:"full_base",default:!0,gains:[4.8,5.76,5.76,3.36,.96,-2.4,-4.8,-6.24,-6.72,-6.72]},{name:"Full Treble",id:"full_treble",default:!0,gains:[-5.76,-5.76,-5.76,-2.4,1.44,6.72,9.6,9.6,9.6,10.08]},{name:"Laptop Speakers",id:"laptop_speakers",default:!0,gains:[2.88,6.72,3.36,-1.92,-1.44,.96,2.88,5.76,7.68,8.64]},{name:"Full Bass & Treble",id:"bass_treble",default:!0,gains:[4.32,3.36,0,-4.32,-2.88,.96,4.8,6.72,7.2,7.2]}];var k=Object.freeze({REACT:"REACT",VANILLA:"VANILLA",DEVELOPMENT:"development"}),l=Object.freeze({BUFFERING:"buffering",PLAYING:"playing",PAUSED:"paused",READY:"ready",IDLE:"idle",ENDED:"ended",STALLED:"stalled",ERROR:"error",TRACK_CHANGE:"trackchanged",DURATION_CHANGE:"durationchanged",QUEUE_ENDED:"queueended"}),b=Object.freeze({MEDIA_ERR_ABORTED:"The user canceled the audio.",MEDIA_ERR_DECODE:"An error occurred while decoding the audio.",MEDIA_ERR_NETWORK:"A network error occurred while fetching the audio.",MEDIA_ERR_SRC_NOT_SUPPORTED:"The audio is missing or is in a format not supported by your browser.",DEFAULT:"An unknown error occurred."}),Q={HLS:"https://cdnjs.cloudflare.com/ajax/libs/hls.js/1.5.11/hls.min.js",CAST:"https://www.gstatic.com/cv/js/sender/v1/cast_sender.js?loadCastFramework=1"};var u,ce=(u=class{static validateEventName(e){if(!e||typeof e!="string")throw new Error("Invalid event name")}static notify(e,t,r="audiox_notifier_default"){this.validateEventName(e);let i=u.listeners[e];i&&t!==null&&(u.notifierState[e]=R(R({},u.notifierState[e]||{}),t),i.forEach(o=>{o(u.notifierState[e]);}));}static listen(e,t,r={}){if(this.validateEventName(e),typeof t!="function")throw new Error("Callback must be a function");return u.listeners[e]?u.listeners[e].add(t):(u.notifierState[e]=r,u.listeners[e]=new Set([t])),()=>{let i=u.listeners[e];i&&(i.delete(t),i.size===0&&delete u.listeners[e]);}}static multiListen(e,t,r={}){if(this.validateEventName(e),!Array.isArray(t)||t.length===0)throw new Error("Callbacks must be a non-empty array of functions");let i=t.map(o=>u.listen(e,o,r));return ()=>{i.forEach(o=>o());}}static getLatestState(e){return this.validateEventName(e),u.notifierState[e]}},n(u,"ChangeNotifier"),c(u,"listeners",{}),c(u,"notifierState",{}),u),f=ce;var T=n(s=>s&&Array.isArray(s)&&s.length,"isValidArray"),X=n(s=>s instanceof Function&&typeof s=="function","isValidFunction");var z={},j=n(s=>{let e="",t=s.error;switch(t==null?void 0:t.code){case MediaError.MEDIA_ERR_ABORTED:e+=b.MEDIA_ERR_ABORTED;break;case MediaError.MEDIA_ERR_NETWORK:e+=b.MEDIA_ERR_NETWORK;break;case MediaError.MEDIA_ERR_DECODE:e+=b.MEDIA_ERR_DECODE;break;case MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED:e+=b.MEDIA_ERR_SRC_NOT_SUPPORTED;break;default:e+=b.DEFAULT;break}return e},"getReadableErrorMessage"),$=n(s=>{var y;let{title:e,album:t,artist:r,artwork:i}=s,o=i?(y=i[0])==null?void 0:y.src:"",_=["96x96","128x128","192x192","256x256","384x384","512x512"].map(P=>({src:o,sizes:P,type:"image/png"}));return {title:e,album:t,artist:r,artwork:_}},"metaDataCreator"),x=0,L=n((s,e)=>{let t=new Set;for(let o=0;o<s.played.length;o++){let E=s.played.start(o),A=s.played.end(o)-E;t.add(A);}let i=[...t].reduce((o,E)=>o+E,0);x=["ENDED","TRACK_CHANGE","PAUSE"].includes(e)?i:x,f.notify("AUDIO_STATE",{currentTrackPlayTime:i,previousTrackPlayTime:x});},"calculateActualPlayedLength"),W=n((s,e,t)=>new Promise((r,i)=>{if(window instanceof Window&&window.document)if(z[t])e(),r();else {z[t]=!0;let o=document.createElement("script");o.type="text/javascript",o.src=s,o.async=!0,o.onload=()=>{e(),r();},document.head.appendChild(o);}else i(`Window not ready unable to initialize ${t}`);}),"loadScript"),J=n(()=>{let s=new h,e=!1,t=n(r=>{if(r.playbackState==="ended"&&!e){let i=s.getQueue();e=!0,i&&T(i)&&e&&s.playNext();}r.playbackState!=="ended"&&(e=!1);},"audioStateListener");f.listen("AUDIO_STATE",t);},"handleQueuePlayback"),m=n(s=>{let{buffered:e}=s,t=0;for(let r=0;r<e.length;r++)t+=e.end(r)-e.start(r);return t},"getBufferedDuration"),Z=n(s=>{let e=[...s];for(let t=e.length-1;t>0;t--){let r=Math.floor(Math.random()*t);[e[t],e[r]]=[e[r],e[t]];}return e},"shuffle"),N=n((s,e)=>{if(s===null&&e===null)return !0;if(s===null||e===null||typeof s!=typeof e)return !1;if(typeof s!="object")return s===e;if(Array.isArray(s)&&Array.isArray(e))return s.length!==e.length?!1:s.every((i,o)=>N(i,e[o]));let t=Object.keys(s),r=Object.keys(e);return t.length!==r.length?!1:t.every(i=>r.includes(i)?N(s[i],e[i]):!1)},"diffChecker");var g,q=(g=class{constructor(){c(this,"audioCtx");c(this,"audioCtxStatus");c(this,"eqFilterBands");c(this,"bassBoostFilter");c(this,"compressor");if(g._instance)return g._instance;this.initializeAudioContext(),g._instance=this;}initializeAudioContext(){let e={latencyHint:"playback"};typeof AudioContext!="undefined"?this.audioCtx=new AudioContext(e):typeof window.webkitAudioContext!="undefined"&&(this.audioCtx=new window.webkitAudioContext(e)),this.audioCtxStatus="ACTIVE",this.init(),this.audioCtx.state==="suspended"&&this.addResumeListener();}addResumeListener(){let e=n(()=>{this.audioCtx.resume(),setTimeout(()=>{this.audioCtx.state==="running"&&document.body.removeEventListener("click",e,!1);},0);},"resume");document.body.addEventListener("click",e,!1);}init(){try{let e=h.getAudioInstance(),t=this.audioCtx.createMediaElementSource(e),r=Y.map(i=>{let o=this.audioCtx.createBiquadFilter();return o.type=i.type,o.frequency.value=i.frequency,o.gain.value=i.gain,o.Q.value=i.q||1,o});this.compressor=this.audioCtx.createDynamicsCompressor(),this.compressor.threshold.value=-24,this.compressor.knee.value=30,this.compressor.ratio.value=12,this.compressor.attack.value=.003,this.compressor.release.value=.25,this.bassBoostFilter=this.audioCtx.createBiquadFilter(),this.bassBoostFilter.type="lowshelf",this.bassBoostFilter.frequency.value=100,this.bassBoostFilter.gain.value=0,t.connect(r[0]);for(let i=0;i<r.length-1;i++)r[i].connect(r[i+1]);r[r.length-1].connect(this.bassBoostFilter),this.bassBoostFilter.connect(this.compressor),this.compressor.connect(this.audioCtx.destination),this.audioCtxStatus="ACTIVE",this.eqFilterBands=r;}catch(e){this.audioCtxStatus="FAILED";}}setPreset(e){let t=F.find(i=>i.id===e);if(!t||!this.eqFilterBands||this.eqFilterBands.length!==t.gains.length)return;let r=this.audioCtx.currentTime;this.eqFilterBands.forEach((i,o)=>{let E=t.gains[o];i.gain.setTargetAtTime(E,r,.05);});}static getPresets(){return F}status(){return this.audioCtx.state==="suspended"&&this.audioCtx.resume(),this.audioCtxStatus}setCustomEQ(e){if(T(e)&&e.length===this.eqFilterBands.length){let t=this.audioCtx.currentTime;this.eqFilterBands.forEach((r,i)=>{r.gain.setTargetAtTime(e[i],t,.05);});}}setBassBoost(e,t=6){let r=this.audioCtx.currentTime;e?this.bassBoostFilter.gain.setTargetAtTime(t,r,.05):this.bassBoostFilter.gain.setTargetAtTime(0,r,.05);}setCompressorSettings(e){this.compressor&&(e.threshold!==void 0&&this.compressor.threshold.setTargetAtTime(e.threshold,this.audioCtx.currentTime,.01),e.knee!==void 0&&this.compressor.knee.setTargetAtTime(e.knee,this.audioCtx.currentTime,.01),e.ratio!==void 0&&this.compressor.ratio.setTargetAtTime(e.ratio,this.audioCtx.currentTime,.01),e.attack!==void 0&&this.compressor.attack.setTargetAtTime(e.attack,this.audioCtx.currentTime,.01),e.release!==void 0&&this.compressor.release.setTargetAtTime(e.release,this.audioCtx.currentTime,.01));}reset(){let e=this.audioCtx.currentTime;this.eqFilterBands.forEach(t=>{t.gain.setTargetAtTime(0,e,.05);}),this.bassBoostFilter.gain.setTargetAtTime(0,e,.05);}},n(g,"Equalizer"),c(g,"_instance"),g);var ee={ERROR:n((s,e)=>{let t=e.type,r=e.details,i=e.fatal;f.notify("AUDIO_STATE",{playbackState:l.ERROR,error:{type:t,isFatal:i,detail:r}},`audiox_baseEvents_state_${s.type}`);},"ERROR"),FRAG_CHANGED:n(()=>{},"FRAG_CHANGED")};var v=Object.freeze({ABORT:"abort",TIME_UPDATE:"timeupdate",CAN_PLAY:"canplay",CAN_PLAY_THROUGH:"canplaythrough",DURATION_CHANGE:"durationchange",ENDED:"ended",EMPTIED:"emptied",PLAYING:"playing",WAITING:"waiting",SEEKING:"seeking",SEEKED:"seeked",LOADED_META_DATA:"loadedmetadata",LOADED_DATA:"loadeddata",PLAY:"play",PAUSE:"pause",RATE_CHANGE:"ratechange",VOLUME_CHANGE:"volumechange",SUSPEND:"suspend",STALLED:"stalled",PROGRESS:"progress",LOAD_START:"loadstart",ERROR:"error",TRACK_CHANGE:"trackchange",QUEUE_ENDED:"queueended"}),te={MEDIA_ATTACHING:"hlsMediaAttaching",MEDIA_ATTACHED:"hlsMediaAttached",MEDIA_DETACHING:"hlsMediaDetaching",MEDIA_DETACHED:"hlsMediaDetached",BUFFER_RESET:"hlsBufferReset",BUFFER_CODECS:"hlsBufferCodecs",BUFFER_CREATED:"hlsBufferCreated",BUFFER_APPENDING:"hlsBufferAppending",BUFFER_APPENDED:"hlsBufferAppended",BUFFER_EOS:"hlsBufferEos",BUFFER_FLUSHING:"hlsBufferFlushing",BUFFER_FLUSHED:"hlsBufferFlushed",MANIFEST_LOADING:"hlsManifestLoading",MANIFEST_LOADED:"hlsManifestLoaded",MANIFEST_PARSED:"hlsManifestParsed",LEVEL_SWITCHING:"hlsLevelSwitching",LEVEL_SWITCHED:"hlsLevelSwitched",LEVEL_LOADING:"hlsLevelLoading",LEVEL_LOADED:"hlsLevelLoaded",LEVEL_UPDATED:"hlsLevelUpdated",LEVEL_PTS_UPDATED:"hlsLevelPtsUpdated",LEVELS_UPDATED:"hlsLevelsUpdated",AUDIO_TRACKS_UPDATED:"hlsAudioTracksUpdated",AUDIO_TRACK_SWITCHING:"hlsAudioTrackSwitching",AUDIO_TRACK_SWITCHED:"hlsAudioTrackSwitched",AUDIO_TRACK_LOADING:"hlsAudioTrackLoading",AUDIO_TRACK_LOADED:"hlsAudioTrackLoaded",SUBTITLE_TRACKS_UPDATED:"hlsSubtitleTracksUpdated",SUBTITLE_TRACKS_CLEARED:"hlsSubtitleTracksCleared",SUBTITLE_TRACK_SWITCH:"hlsSubtitleTrackSwitch",SUBTITLE_TRACK_LOADING:"hlsSubtitleTrackLoading",SUBTITLE_TRACK_LOADED:"hlsSubtitleTrackLoaded",SUBTITLE_FRAG_PROCESSED:"hlsSubtitleFragProcessed",CUES_PARSED:"hlsCuesParsed",NON_NATIVE_TEXT_TRACKS_FOUND:"hlsNonNativeTextTracksFound",INIT_PTS_FOUND:"hlsInitPtsFound",FRAG_LOADING:"hlsFragLoading",FRAG_LOAD_EMERGENCY_ABORTED:"hlsFragLoadEmergencyAborted",FRAG_LOADED:"hlsFragLoaded",FRAG_DECRYPTED:"hlsFragDecrypted",FRAG_PARSING_INIT_SEGMENT:"hlsFragParsingInitSegment",FRAG_PARSING_USERDATA:"hlsFragParsingUserdata",FRAG_PARSING_METADATA:"hlsFragParsingMetadata",FRAG_PARSED:"hlsFragParsed",FRAG_BUFFERED:"hlsFragBuffered",FRAG_CHANGED:"hlsFragChanged",FPS_DROP:"hlsFpsDrop",FPS_DROP_LEVEL_CAPPING:"hlsFpsDropLevelCapping",ERROR:"hlsError",DESTROYING:"hlsDestroying",KEY_LOADING:"hlsKeyLoading",KEY_LOADED:"hlsKeyLoaded",LIVE_BACK_BUFFER_REACHED:"hlsLiveBackBufferReached",BACK_BUFFER_REACHED:"hlsBackBufferReached"};var H=n((s,e=!1)=>{let t=h.getAudioInstance();T(Object.keys(s))&&Object.keys(s).forEach(r=>{let i=r;t==null||t.addEventListener(v[i],o=>{if(r&&s[i]){let E=s[i];typeof E=="function"&&E(o,t,e);}});});},"attachEventListeners");var se=n((s,e=!1)=>{let r=new C().getHlsInstance();T(Object.keys(s))&&Object.keys(s).forEach(i=>{let o=i;r.on(te[o],(E,_)=>{if(o&&s[o]){let A=s[o];typeof A=="function"&&A(E,_,r,e);}});});},"attachHlsEventsListeners");var O,S,ue=(S=class{constructor(){c(this,"HlsClass");if(S._instance)return S._instance;S._instance=this;}load(){return p(this,null,function*(){return yield W(Q.HLS,()=>{},"hls").then(()=>{this.HlsClass=window.Hls,window.Hls=void 0;}).catch(e=>{}),this.HlsClass})}init(){return p(this,arguments,function*(e={},t){let r=yield this.load();r.isSupported()&&(O=new r(e),se(ee,t));})}addHlsMedia(e){let t=this.HlsClass,r=h.getAudioInstance();O.loadSource(e.source),O.attachMedia(r),O.on(t.Events.MEDIA_ATTACHED,function(){});}getHlsInstance(){return O}},n(S,"HlsAdapter"),c(S,"_instance"),S),C=ue;var re=Object.freeze({1:"MEDIA_ERR_ABORTED",3:"MEDIA_ERR_DECODE",2:"MEDIA_ERR_NETWORK",4:"MEDIA_ERR_SRC_NOT_SUPPORTED"});var d=f,ie={LOAD_START:n((s,e)=>{let t=m(e);d.notify("AUDIO_STATE",{playbackState:l.BUFFERING,duration:e==null?void 0:e.duration,error:{code:null,message:"",readable:""},bufferedDuration:t},`audiox_baseEvents_state_${s.type}`);},"LOAD_START"),DURATION_CHANGE:n((s,e)=>{let t=d.getLatestState("AUDIO_X_STATE"),r=m(e);d.notify("AUDIO_STATE",{playbackState:t.playbackState==="playing"?l.PLAYING:l.DURATION_CHANGE,duration:e==null?void 0:e.duration,error:{code:null,message:"",readable:""},bufferedDuration:r},`audiox_baseEvents_state_${s.type}`);},"DURATION_CHANGE"),LOADED_META_DATA:n((s,e)=>{let t=m(e);d.notify("AUDIO_STATE",{playbackState:l.BUFFERING,duration:e==null?void 0:e.duration,error:{code:null,message:"",readable:""},bufferedDuration:t},`audiox_baseEvents_state_${s.type}`);},"LOADED_META_DATA"),LOADED_DATA:n((s,e)=>{let t=m(e);d.notify("AUDIO_STATE",{playbackState:l.BUFFERING,duration:e==null?void 0:e.duration,error:{code:null,message:"",readable:""},bufferedDuration:t},`audiox_baseEvents_state_${s.type}`);},"LOADED_DATA"),CAN_PLAY:n((s,e)=>{let t=d.getLatestState("AUDIO_X_STATE"),r=m(e);d.notify("AUDIO_STATE",{playbackState:t.playbackState==="paused"?l.PAUSED:l.READY,error:{code:null,message:"",readable:""},bufferedDuration:r},`audiox_baseEvents_state_${s.type}`);},"CAN_PLAY"),CAN_PLAY_THROUGH:n((s,e)=>{let t=d.getLatestState("AUDIO_X_STATE"),r=e.paused,i=m(e);d.notify("AUDIO_STATE",{playbackState:r?l.PAUSED:t.playbackState==="playing"?l.PLAYING:l.READY,error:{code:null,message:"",readable:""},bufferedDuration:i},`audiox_baseEvents_state_${s.type}`);},"CAN_PLAY_THROUGH"),PLAY:n((s,e)=>{d.notify("AUDIO_STATE",{playbackState:l.PLAYING,progress:e==null?void 0:e.currentTime,error:{code:null,message:"",readable:""}},`audiox_baseEvents_state_${s.type}`);},"PLAY"),PLAYING:n((s,e)=>{d.notify("AUDIO_STATE",{playbackState:l.PLAYING,progress:e==null?void 0:e.currentTime,error:{code:null,message:"",readable:""}},`audiox_baseEvents_state_${s.type}`);},"PLAYING"),PAUSE:n((s,e,t)=>{d.notify("AUDIO_STATE",{playbackState:l.PAUSED,progress:e==null?void 0:e.currentTime,error:{code:null,message:"",readable:""}},`audiox_baseEvents_state_${s.type}`),t&&L(e,"PAUSE");},"PAUSE"),ENDED:n((s,e,t)=>{d.notify("AUDIO_STATE",{playbackState:l.ENDED,progress:e==null?void 0:e.currentTime,error:{code:null,message:"",readable:""}},`audiox_baseEvents_state_${s.type}`),t&&L(e,"ENDED");},"ENDED"),ERROR:n((s,e)=>{var i;let t=(i=e.error)==null?void 0:i.code,r=j(e);d.notify("AUDIO_STATE",{playbackState:l.ERROR,error:{code:t,message:re[t],readable:r}},`audiox_baseEvents_state_${s.type}`);},"ERROR"),TIME_UPDATE:n((s,e)=>{let t=d.getLatestState("AUDIO_X_STATE"),r=m(e);d.notify("AUDIO_STATE",{playbackState:e.paused?t==null?void 0:t.playbackState:l.PLAYING,progress:e==null?void 0:e.currentTime,error:{code:null,message:"",readable:""},bufferedDuration:r},`audiox_baseEvents_state_${s.type}`);},"TIME_UPDATE"),WAITING:n((s,e)=>{d.notify("AUDIO_STATE",{playbackState:l.BUFFERING,progress:e==null?void 0:e.currentTime,error:{code:null,message:"",readable:""}},`audiox_baseEvents_state_${s.type}`);},"WAITING"),VOLUME_CHANGE:n(s=>{d.notify("AUDIO_STATE",{},"audiox_baseEvents_state");},"VOLUME_CHANGE"),SEEKED:n((s,e)=>{let t=d.getLatestState("AUDIO_X_STATE"),r=m(e);d.notify("AUDIO_STATE",{playbackState:t.playbackState==="paused"?"paused":t.playbackState,progress:e==null?void 0:e.currentTime,error:{code:null,message:"",readable:""},bufferedDuration:r},`audiox_baseEvents_state_${s.type}`);},"SEEKED")};var ae=n(s=>{"mediaSession"in navigator&&(navigator.mediaSession.metadata=new MediaMetadata($(s)));},"updateMetaData"),w=n(()=>{let s=new h;"mediaSession"in navigator&&(navigator.mediaSession.setActionHandler("play",()=>{h.getAudioInstance().play();}),navigator.mediaSession.setActionHandler("pause",()=>{h.getAudioInstance().pause();}),s.getQueue().length&&(navigator.mediaSession.setActionHandler("previoustrack",()=>{s.playPrevious();}),navigator.mediaSession.setActionHandler("nexttrack",()=>{s.playNext();})));},"attachMediaSessionHandlers");var G={HAVE_NOTHING:0,HAVE_METADATA:1,HAVE_CURRENT_DATA:2,HAVE_FUTURE_DATA:3,HAVE_ENOUGH_DATA:4},B={playbackState:l.IDLE,duration:0,bufferedDuration:0,progress:0,volume:50,playbackRate:1,error:{code:null,message:"",readable:""},currentTrack:{},currentTrackPlayTime:0,previousTrackPlayTime:0};f.listen("AUDIO_STATE",s=>{let e=f.getLatestState("AUDIO_X_STATE");N(e,s)||f.notify("AUDIO_X_STATE",R(R({},B),s));},B);var a,U=f,D,h=(D=class{constructor(){c(this,"_audio");c(this,"isPlayLogEnabled");c(this,"_queue");c(this,"_currentQueueIndex",0);c(this,"_fetchFn");c(this,"eqStatus","IDEAL");c(this,"isEqEnabled",!1);c(this,"eqInstance");c(this,"showNotificationsActions",!1);var e;if(D._instance)return D._instance;if(process.env.NODE_ENV!==((e=k)==null?void 0:e.DEVELOPMENT)&&a)throw new Error("Cannot create multiple audio instance");D._instance=this,this._audio=new Audio,a=this._audio;}init(e){return p(this,null,function*(){var M;let{preloadStrategy:t="auto",autoPlay:r=!1,useDefaultEventListeners:i=!0,customEventListeners:o=null,showNotificationActions:E=!1,enablePlayLog:_=!1,enableHls:A=!1,enableEQ:y=!1,crossOrigin:P="anonymous",hlsConfig:oe={}}=e;(M=this._audio)==null||M.setAttribute("id","audio_x_instance"),this._audio.preload=t,this._audio.autoplay=r,this._audio.crossOrigin=P,this.isPlayLogEnabled=_,this.isEqEnabled=y,o!==null?H(o,!1):H(ie,_),E&&(this.showNotificationsActions=!0,w()),A&&new C().init(oe,_);})}addMedia(e){return p(this,null,function*(){if(!e)return;let t=this.getQueue();if(T(t)){let i=t.findIndex(o=>e.id===o.id);i>-1&&(this._currentQueueIndex=i);}let r=e.source.includes(".m3u8")?"HLS":"DEFAULT";if(this.isPlayLogEnabled&&L(a,"TRACK_CHANGE"),r==="HLS"){let i=new C,o=i.getHlsInstance();o?(o.detachMedia(),i.addHlsMedia(e)):yield this.reset();}else a.src=e.source;U.notify("AUDIO_STATE",{playbackState:l.TRACK_CHANGE,currentTrackPlayTime:0,currentTrack:e}),ae(e),a.load();})}attachEq(){if(this.eqStatus==="IDEAL")try{let e=new q;this.eqStatus=e.status(),this.eqInstance=e;}catch(e){}}play(){return p(this,null,function*(){let e=a.src!=="";a!=null&&a.paused&&a.HAVE_ENOUGH_DATA===G.HAVE_ENOUGH_DATA&&e&&(yield a.play().then(()=>{}).catch(()=>{})),this.isEqEnabled&&this.attachEq();})}addMediaAndPlay(e,t){return p(this,null,function*(){let r=e||(this._queue.length>0?this._queue[0]:void 0);t&&X(t)&&r&&(this._fetchFn=t,yield t(r));try{r&&this.addMedia(r).then(()=>{a.HAVE_ENOUGH_DATA===G.HAVE_ENOUGH_DATA&&setTimeout(()=>p(this,null,function*(){yield this.play(),this.isEqEnabled&&this.attachEq();}),950);});}catch(i){}})}pause(){a&&!(a!=null&&a.paused)&&(a==null||a.pause());}stop(){a&&!a.paused&&(a==null||a.pause(),a.currentTime=0);}reset(){return p(this,null,function*(){a&&(this.stop(),a.src="",a.srcObject=null);})}setVolume(e){let t=e/100;a&&(a.volume=t,U.notify("AUDIO_STATE",{volume:e}));}setPlaybackRate(e){a&&(a.playbackRate=e,U.notify("AUDIO_STATE",{playbackRate:e}));}mute(){a&&!a.muted&&(a.muted=!0);}seek(e){a&&(a.currentTime=e);}seekBy(e){if(a&&a.currentTime){let t=a.currentTime;a.currentTime=t+e;}}destroy(){return p(this,null,function*(){a&&(yield this.reset(),a.removeAttribute("src"),a.load());})}subscribe(e,t,r={}){return U.listen(e,t,r)}addEventListener(e,t){a.addEventListener(e,t);}getPresets(){return q.getPresets()}setPreset(e){this.isEqEnabled&&this.eqInstance.setPreset(e);}setCustomEQ(e){this.isEqEnabled&&this.eqInstance.setCustomEQ(e);}setBassBoost(e,t){this.isEqEnabled&&this.eqInstance.setBassBoost(e,t);}addQueue(e,t){this.clearQueue();let r=T(e)?e.slice():[];switch(t){case"DEFAULT":this._queue=r;break;case"REVERSE":this._queue=r.reverse();break;case"SHUFFLE":this._queue=Z(r);break;default:this._queue=r;break}J(),this.showNotificationsActions&&w();}playNext(){let e=this._currentQueueIndex+1;if(this._queue.length>e){let t=this._queue[e];this.addMediaAndPlay(t,this._fetchFn),this._currentQueueIndex=e;}else this.stop(),U.notify("AUDIO_STATE",{playbackState:l.QUEUE_ENDED});}playPrevious(){let e=this._currentQueueIndex-1;if(e>=0){let t=this._queue[e];this.addMediaAndPlay(t,this._fetchFn),this._currentQueueIndex=e;}}clearQueue(){this._queue&&T(this._queue)&&(this._queue=[],this._currentQueueIndex=0);}addToQueue(e){this._queue&&T(this._queue)&&(Array.isArray(e)?this._queue=[...this._queue,...e]:this._queue.push(e));}removeFromQueue(e){if(this._queue&&T(this._queue)){let t=this._queue.filter(r=>r.id==e.id);this._queue=t;}}getQueue(){return this._queue&&T(this._queue)?this._queue:[]}get id(){return a==null?void 0:a.getAttribute("id")}static getAudioInstance(){return a}},n(D,"AudioX"),c(D,"_instance"),D); | ||
export { w as AUDIO_EVENTS, v as AUDIO_STATE, k as AUDIO_X_CONSTANTS, T as AudioX }; | ||
export { v as AUDIO_EVENTS, B as AUDIO_STATE, k as AUDIO_X_CONSTANTS, h as AudioX }; | ||
//# sourceMappingURL=index.js.map | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "audio_x", | ||
"version": "1.0.10-beta.10", | ||
"version": "1.0.10-beta.11", | ||
"description": "The audio player for the gen-x", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
250628
3300