1159cl/lib/icecast-metadata-player-1.17.3.main.min.js
Mario1159 5b6b79892c
Some checks failed
Release / test (push) Failing after 51s
Release / push-docker-image (push) Has been skipped
2024 new version
2024-12-06 20:38:18 -03:00

23 lines
63 KiB
JavaScript
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*! For license information please see icecast-metadata-player-1.17.3.main.min.js.LICENSE.txt */
/*!
* Copyright 2021-2023 Ethan Halsall
* https://github.com/eshaz/icecast-metadata-js
*
* This file is part of icecast-metadata-player.
*
* icecast-metadata-player free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* icecast-metadata-player distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>
*/
var IcecastMetadataPlayer;(()=>{"use strict";var t,s,i,e={317:(t,s,i)=>{i.d(s,{fp:()=>re,HQ:()=>ne,p:()=>ae,Ay:()=>he,wx:()=>oe,we:()=>ce,cJ:()=>de,Er:()=>ue,$:()=>le});const e=Symbol,h=(()=>{const t="left",s="center",i="right";return["","front ","side ","rear "].map((e=>[[t,i],[t,i,s],[t,s,i],[s,t,i],[s]].flatMap((t=>t.map((t=>e+t)).join(", ")))))})(),r="LFE",n="monophonic (mono)",a="stereo",o="surround",c=(t,...s)=>`${[n,a,`linear ${o}`,"quadraphonic",`5.0 ${o}`,`5.1 ${o}`,`6.1 ${o}`,`7.1 ${o}`][t-1]} (${s.join(", ")})`,u=[n,c(2,h[0][0]),c(3,h[0][2]),c(4,h[1][0],h[3][0]),c(5,h[1][2],h[3][0]),c(6,h[1][2],h[3][0],r),c(7,h[1][2],h[2][0],h[3][4],r),c(8,h[1][2],h[2][0],h[3][0],r)],l=48e3,d=44100,y=32e3,f=24e3,m=22050,p=16e3,w=8e3,g="absoluteGranulePosition",b="bandwidth",S="bitDepth",q="bitrate",M=q+"Maximum",A=q+"Minimum",v=q+"Nominal",P="buffer",E=P+"Fullness",_="codec",T=_+"Frames",C="coupledStreamCount",I="crc",R=I+"16",x=I+"32",$="data",k="description",O="duration",D="emphasis",B="hasOpusPadding",L="header",U="isContinuedPacket",F="isCopyrighted",N="isFirstPage",j="isHome",W="isLastPage",G="isOriginal",H="isPrivate",Q="isVbr",V="layer",Y="length",z="mode",K=z+"Extension",J="mpeg",Z=J+"Version",X="numberAACFrames",tt="outputGain",st="preSkip",it="profile",et=e(),ht="protection",rt="rawData",nt="segments",at="subarray",ot="version",ct="vorbis",ut=ct+"Comments",lt=ct+"Setup",dt="block",yt=dt+"ingStrategy",ft=e(),mt=dt+"Size",pt=dt+"size0",wt=dt+"size1",gt=e(),bt="channel",St=bt+"MappingFamily",qt=bt+"MappingTable",Mt=bt+"Mode",At=e(),vt=bt+"s",Pt="copyright",Et=Pt+"Id",_t=Pt+"IdStart",Tt="frame",Ct=Tt+"Count",It=Tt+"Length",Rt="Number",xt=Tt+Rt,$t=Tt+"Padding",kt=Tt+"Size",Ot="Rate",Dt="inputSample"+Ot,Bt="page",Lt=Bt+"Checksum",Ut=e(),Ft=Bt+"SegmentTable",Nt=Bt+"Sequence"+Rt,jt="sample",Wt=jt+Rt,Gt=jt+Ot,Ht=e(),Qt=jt+"s",Vt="stream",Yt=Vt+"Count",zt=Vt+"Info",Kt=Vt+"Serial"+Rt,Jt=Vt+"StructureVersion",Zt="total",Xt=Zt+"BytesOut",ts=Zt+"Duration",ss=Zt+"Samples",is=e(),es=e(),hs=e(),rs=e(),ns=e(),as=e(),os=e(),cs=e(),us=e(),ls=e(),ds=e(),ys=e(),fs=e(),ms=e(),ps=e(),ws=e(),gs=e(),bs=e(),Ss=Uint8Array,qs=DataView,Ms="reserved",As="bad",vs="free",Ps="none",Es="16bit CRC",_s=(t,s,i)=>{for(let e=0;e<t[Y];e++){let h=s(e);for(let t=8;t>0;t--)h=i(h);t[e]=h}return t},Ts=_s(new Ss(256),(t=>t),(t=>128&t?7^t<<1:t<<1)),Cs=[_s(new Uint16Array(256),(t=>t<<8),(t=>t<<1^(32768&t?32773:0)))],Is=[_s(new Uint32Array(256),(t=>t),(t=>t>>>1^3988292384*(1&t)))];for(let t=0;t<15;t++){Cs.push(new Uint16Array(256)),Is.push(new Uint32Array(256));for(let s=0;s<=255;s++)Cs[t+1][s]=Cs[0][Cs[t][s]>>>8]^Cs[t][s]<<8,Is[t+1][s]=Is[t][s]>>>8^Is[0][255&Is[t][s]]}const Rs=t=>{const s=t[Y],i=s-16;let e=0,h=0;for(;h<=i;)e=Is[15][255&(t[h++]^e)]^Is[14][255&(t[h++]^e>>>8)]^Is[13][255&(t[h++]^e>>>16)]^Is[12][t[h++]^e>>>24]^Is[11][t[h++]]^Is[10][t[h++]]^Is[9][t[h++]]^Is[8][t[h++]]^Is[7][t[h++]]^Is[6][t[h++]]^Is[5][t[h++]]^Is[4][t[h++]]^Is[3][t[h++]]^Is[2][t[h++]]^Is[1][t[h++]]^Is[0][t[h++]];for(;h!==s;)e=Is[0][255&(e^t[h++])]^e>>>8;return~e},xs=(...t)=>{const s=new Ss(t.reduce(((t,s)=>t+s[Y]),0));return t.reduce(((t,i)=>(s.set(i,t),t+i[Y])),0),s},$s=t=>String.fromCharCode(...t),ks=[0,8,4,12,2,10,6,14,1,9,5,13,3,11,7,15],Os=t=>ks[15&t]<<4|ks[t>>4];class Ds{constructor(t){this.t=t,this.i=8*t[Y]}set position(t){this.i=t}get position(){return this.i}read(t){const s=Math.floor(this.i/8),i=this.i%8;this.i-=t;return(Os(this.t[s-1])<<8)+Os(this.t[s])>>7-i&255}}class Bs{constructor(t,s){this.h=t,this.S=s,this[ps]()}[ws](){this.q=!0}[ps](){this.M=new Map,this.A=new WeakMap,this.v=!1,this.P=!1,this._=null,this.q=!1}[ms](t,s){if(this.S){this._!==t&&(this._=t,this.P=!0);const i=this.A.get(this.M.get(this.T));this.P&&i&&this.S({bitrate:t,...i},s),this.P=!1}}[us](t){const s=this.M.get(t);return s&&this.C(t),s}[ls](t,s,i){this.q&&(this.v||(this.h({...s}),this.v=!0),this.C(t),this.M.set(t,s),this.A.set(s,i))}C(t){this.S&&t!==this.T&&(this.P=!0,this.T=t)}}const Ls=new WeakMap,Us=new WeakMap;class Fs{constructor(t,s){this.I=t,this.M=s}*[os](){let t;for(;;){if(t=yield*this.Frame[ds](this.I,this.M,0),t)return t;this.I[es](1)}}*[cs](t){let s=yield*this[os]();const i=Us.get(s)[Y];if(t||this.I.R||(yield*this.Header[us](this.I,this.M,i)))return this.M[ws](),this.I[es](i),this.I[rs](s),s;this.I[ns](`Missing ${Tt} at ${i} bytes from current position.`,`Dropping current ${Tt} and trying again.`),this.M[ps](),this.I[es](1)}}class Ns{constructor(t,s){Us.set(this,{[L]:t}),this[$]=s}}class js extends Ns{static*[ds](t,s,i,e,h){const r=yield*t[us](i,e,h);if(r){const t=Ls.get(r)[It],e=Ls.get(r)[Qt];return new s(r,(yield*i[is](t,h))[at](0,t),e)}return null}constructor(t,s,i){super(t,s),this[L]=t,this[Qt]=i,this[O]=i/t[Gt]*1e3,this[xt]=null,this[Xt]=null,this[ss]=null,this[ts]=null,Us.get(this)[Y]=s[Y]}}const Ws="unsynchronizationFlag",Gs="extendedHeaderFlag",Hs="experimentalFlag",Qs="footerPresent";class Vs{static*getID3v2Header(t,s,i){const e={};let h=yield*t[is](3,i);if(73!==h[0]||68!==h[1]||51!==h[2])return null;if(h=yield*t[is](10,i),e[ot]=`id3v2.${h[3]}.${h[4]}`,15&h[5])return null;if(e[Ws]=!!(128&h[5]),e[Gs]=!!(64&h[5]),e[Hs]=!!(32&h[5]),e[Qs]=!!(16&h[5]),128&h[6]||128&h[7]||128&h[8]||128&h[9])return null;const r=h[6]<<21|h[7]<<14|h[8]<<7|h[9];return e[Y]=10+r,new Vs(e)}constructor(t){this[ot]=t[ot],this[Ws]=t[Ws],this[Gs]=t[Gs],this[Hs]=t[Hs],this[Qs]=t[Qs],this[Y]=t[Y]}}class Ys{constructor(t){Ls.set(this,t),this[S]=t[S],this[q]=null,this[vt]=t[vt],this[Mt]=t[Mt],this[Gt]=t[Gt]}}const zs={0:[vs,vs,vs,vs,vs],16:[32,32,32,32,8],240:[As,As,As,As,As]},Ks=(t,s,i)=>8*((t+i)%s+s)*(1<<(t+i)/s)-8*s*(s/8|0);for(let t=2;t<15;t++)zs[t<<4]=[32*t,Ks(t,4,0),Ks(t,4,-1),Ks(t,8,4),Ks(t,8,0)];const Js="bands ",Zs=" to 31",Xs={0:Js+4+Zs,16:Js+8+Zs,32:Js+12+Zs,48:Js+16+Zs},ti="bitrateIndex",si="v2",ii="v1",ei="Intensity stereo ",hi=", MS stereo ",ri="on",ni="off",ai={0:ei+ni+hi+ni,16:ei+ri+hi+ni,32:ei+ni+hi+ri,48:ei+ri+hi+ri},oi={0:{[k]:Ms},2:{[k]:"Layer III",[$t]:1,[K]:ai,[ii]:{[ti]:2,[Qt]:1152},[si]:{[ti]:4,[Qt]:576}},4:{[k]:"Layer II",[$t]:1,[K]:Xs,[Qt]:1152,[ii]:{[ti]:1},[si]:{[ti]:4}},6:{[k]:"Layer I",[$t]:4,[K]:Xs,[Qt]:384,[ii]:{[ti]:0},[si]:{[ti]:3}}},ci="MPEG Version ",ui="ISO/IEC ",li={0:{[k]:`${ci}2.5 (later extension of MPEG 2)`,[V]:si,[Gt]:{0:11025,4:12e3,8:w,12:Ms}},8:{[k]:Ms},16:{[k]:`${ci}2 (${ui}13818-3)`,[V]:si,[Gt]:{0:m,4:f,8:p,12:Ms}},24:{[k]:`${ci}1 (${ui}11172-3)`,[V]:ii,[Gt]:{0:d,4:l,8:y,12:Ms}},length:Y},di={0:Es,1:Ps},yi={0:Ps,1:"50/15 ms",2:Ms,3:"CCIT J.17"},fi={0:{[vt]:2,[k]:a},64:{[vt]:2,[k]:"joint "+a},128:{[vt]:2,[k]:"dual channel"},192:{[vt]:1,[k]:n}};class mi extends Ys{static*[us](t,s,i){const e={},h=yield*Vs.getID3v2Header(t,s,i);h&&(yield*t[is](h[Y],i),t[es](h[Y]));const r=yield*t[is](4,i),n=$s(r[at](0,4)),a=s[us](n);if(a)return new mi(a);if(255!==r[0]||r[1]<224)return null;const o=li[24&r[1]];if(o[k]===Ms)return null;const c=6&r[1];if(oi[c][k]===Ms)return null;const u={...oi[c],...oi[c][o[V]]};if(e[Z]=o[k],e[V]=u[k],e[Qt]=u[Qt],e[ht]=di[1&r[1]],e[Y]=4,e[q]=zs[240&r[2]][u[ti]],e[q]===As)return null;if(e[Gt]=o[Gt][12&r[2]],e[Gt]===Ms)return null;if(e[$t]=2&r[2]&&u[$t],e[H]=!!(1&r[2]),e[It]=Math.floor(125*e[q]*e[Qt]/e[Gt]+e[$t]),!e[It])return null;const l=192&r[3];if(e[Mt]=fi[l][k],e[vt]=fi[l][vt],e[K]=u[K][48&r[3]],e[F]=!!(8&r[3]),e[G]=!!(4&r[3]),e[D]=yi[3&r[3]],e[D]===Ms)return null;e[S]=16;{const{length:t,frameLength:i,samples:h,...r}=e;s[ls](n,e,r)}return new mi(e)}constructor(t){super(t),this[q]=t[q],this[D]=t[D],this[$t]=t[$t],this[F]=t[F],this[G]=t[G],this[H]=t[H],this[V]=t[V],this[K]=t[K],this[Z]=t[Z],this[ht]=t[ht]}}class pi extends js{static*[ds](t,s,i){return yield*super[ds](mi,pi,t,s,i)}constructor(t,s,i){super(t,s,i)}}class wi extends Fs{constructor(t,s,i){super(t,s),this.Frame=pi,this.Header=mi,i(this[_])}get[_](){return J}*[ys](){return yield*this[cs]()}}const gi={0:"MPEG-4",8:"MPEG-2"},bi={0:"valid",2:As,4:As,6:As},Si={0:Es,1:Ps},qi={0:"AAC Main",64:"AAC LC (Low Complexity)",128:"AAC SSR (Scalable Sample Rate)",192:"AAC LTP (Long Term Prediction)"},Mi={0:96e3,4:88200,8:64e3,12:l,16:d,20:y,24:f,28:m,32:p,36:12e3,40:11025,44:w,48:7350,52:Ms,56:Ms,60:"frequency is written explicitly"},Ai={0:{[vt]:0,[k]:"Defined in AOT Specific Config"},64:{[vt]:1,[k]:n},128:{[vt]:2,[k]:c(2,h[0][0])},192:{[vt]:3,[k]:c(3,h[1][3])},256:{[vt]:4,[k]:c(4,h[1][3],h[3][4])},320:{[vt]:5,[k]:c(5,h[1][3],h[3][0])},384:{[vt]:6,[k]:c(6,h[1][3],h[3][0],r)},448:{[vt]:8,[k]:c(8,h[1][3],h[2][0],h[3][0],r)}};class vi extends Ys{static*[us](t,s,i){const e={},h=yield*t[is](7,i),r=$s([h[0],h[1],h[2],252&h[3]|3&h[6]]),n=s[us](r);if(n)Object.assign(e,n);else{if(255!==h[0]||h[1]<240)return null;if(e[Z]=gi[8&h[1]],e[V]=bi[6&h[1]],e[V]===As)return null;const t=1&h[1];e[ht]=Si[t],e[Y]=t?7:9,e[et]=192&h[2],e[Ht]=60&h[2];const i=2&h[2];if(e[it]=qi[e[et]],e[Gt]=Mi[e[Ht]],e[Gt]===Ms)return null;e[H]=!!i,e[At]=448&(h[2]<<8|h[3]),e[Mt]=Ai[e[At]][k],e[vt]=Ai[e[At]][vt],e[G]=!!(32&h[3]),e[j]=!!(8&h[3]),e[Et]=!!(8&h[3]),e[_t]=!!(4&h[3]),e[S]=16,e[Qt]=1024,e[X]=3&h[6];{const{length:t,channelModeBits:i,profileBits:h,sampleRateBits:n,frameLength:a,samples:o,numberAACFrames:c,...u}=e;s[ls](r,e,u)}}if(e[It]=8191&(h[3]<<11|h[4]<<3|h[5]>>5),!e[It])return null;const a=2047&(h[5]<<6|h[6]>>2);return e[E]=2047===a?"VBR":a,new vi(e)}constructor(t){super(t),this[Et]=t[Et],this[_t]=t[_t],this[E]=t[E],this[j]=t[j],this[G]=t[G],this[H]=t[H],this[V]=t[V],this[Y]=t[Y],this[Z]=t[Z],this[X]=t[X],this[it]=t[it],this[ht]=t[ht]}get audioSpecificConfig(){const t=Ls.get(this),s=t[et]+64<<5|t[Ht]<<5|t[At]>>3,i=new Ss(2);return new qs(i[P]).setUint16(0,s,!1),i}}class Pi extends js{static*[ds](t,s,i){return yield*super[ds](vi,Pi,t,s,i)}constructor(t,s,i){super(t,s,i)}}class Ei extends Fs{constructor(t,s,i){super(t,s),this.Frame=Pi,this.Header=vi,i(this[_])}get[_](){return"aac"}*[ys](){return yield*this[cs]()}}class _i extends js{static k(t){return(t[t[Y]-2]<<8)+t[t[Y]-1]}static[bs](t){const s=_i.k(t),i=(t=>{const s=t[Y],i=s-16;let e=0,h=0;for(;h<=i;)e^=t[h++]<<8|t[h++],e=Cs[15][e>>8]^Cs[14][255&e]^Cs[13][t[h++]]^Cs[12][t[h++]]^Cs[11][t[h++]]^Cs[10][t[h++]]^Cs[9][t[h++]]^Cs[8][t[h++]]^Cs[7][t[h++]]^Cs[6][t[h++]]^Cs[5][t[h++]]^Cs[4][t[h++]]^Cs[3][t[h++]]^Cs[2][t[h++]]^Cs[1][t[h++]]^Cs[0][t[h++]];for(;h!==s;)e=(255&e)<<8^Cs[0][e>>8^t[h++]];return e})(t[at](0,-2));return s===i}constructor(t,s,i){s[zt]=i,s[R]=_i.k(t),super(s,t,Ls.get(s)[Qt])}}const Ti="get from STREAMINFO metadata block",Ci={0:"Fixed",1:"Variable"},Ii={0:Ms,16:192};for(let t=2;t<16;t++)Ii[t<<4]=t<6?576*2**(t-2):2**t;const Ri={0:Ti,1:88200,2:176400,3:192e3,4:w,5:p,6:m,7:f,8:y,9:d,10:l,11:96e3,15:As},xi={0:{[vt]:1,[k]:n},16:{[vt]:2,[k]:c(2,h[0][0])},32:{[vt]:3,[k]:c(3,h[0][1])},48:{[vt]:4,[k]:c(4,h[1][0],h[3][0])},64:{[vt]:5,[k]:c(5,h[1][1],h[3][0])},80:{[vt]:6,[k]:c(6,h[1][1],r,h[3][0])},96:{[vt]:7,[k]:c(7,h[1][1],r,h[3][4],h[2][0])},112:{[vt]:8,[k]:c(8,h[1][1],r,h[3][0],h[2][0])},128:{[vt]:2,[k]:`${a} (left, diff)`},144:{[vt]:2,[k]:`${a} (diff, right)`},160:{[vt]:2,[k]:`${a} (avg, diff)`},176:Ms,192:Ms,208:Ms,224:Ms,240:Ms},$i={0:Ti,2:8,4:12,6:Ms,8:16,10:20,12:24,14:Ms};class ki extends Ys{static D(t){if(t[0]>254)return null;if(t[0]<128)return{value:t[0],length:1};let s=1;for(let i=64;i&t[0];i>>=1)s++;let i=s-1,e=0,h=0;for(;i>0;h+=6,i--){if(128!=(192&t[i]))return null;e|=(63&t[i])<<h}return e|=(t[i]&127>>s)<<h,{value:e,length:s}}static[gs](t,s){const i={[is]:function*(){return t}};return ki[us](i,s,0).next().value}static*[us](t,s,i){let e=yield*t[is](6,i);if(255!==e[0]||248!==e[1]&&249!==e[1])return null;const h={},r=$s(e[at](0,4)),n=s[us](r);if(n)Object.assign(h,n);else{if(h[ft]=1&e[1],h[yt]=Ci[h[ft]],h[gt]=240&e[2],h[Ht]=15&e[2],h[mt]=Ii[h[gt]],h[mt]===Ms)return null;if(h[Gt]=Ri[h[Ht]],h[Gt]===As)return null;if(1&e[3])return null;const t=xi[240&e[3]];if(t===Ms)return null;if(h[vt]=t[vt],h[Mt]=t[k],h[S]=$i[14&e[3]],h[S]===Ms)return null}h[Y]=5,e=yield*t[is](h[Y]+8,i);const a=ki.D(e[at](4));if(!a)return null;if(h[ft]?h[Wt]=a.value:h[xt]=a.value,h[Y]+=a[Y],96===h[gt]?(e[Y]<h[Y]&&(e=yield*t[is](h[Y],i)),h[mt]=e[h[Y]-1]+1,h[Y]+=1):112===h[gt]&&(e[Y]<h[Y]&&(e=yield*t[is](h[Y],i)),h[mt]=(e[h[Y]-1]<<8)+e[h[Y]]+1,h[Y]+=2),h[Qt]=h[mt],12===h[Ht]?(e[Y]<h[Y]&&(e=yield*t[is](h[Y],i)),h[Gt]=1e3*e[h[Y]-1],h[Y]+=1):13===h[Ht]?(e[Y]<h[Y]&&(e=yield*t[is](h[Y],i)),h[Gt]=(e[h[Y]-1]<<8)+e[h[Y]],h[Y]+=2):14===h[Ht]&&(e[Y]<h[Y]&&(e=yield*t[is](h[Y],i)),h[Gt]=10*((e[h[Y]-1]<<8)+e[h[Y]]),h[Y]+=2),e[Y]<h[Y]&&(e=yield*t[is](h[Y],i)),h[I]=e[h[Y]-1],h[I]!==(t=>{let s=0;const i=t[Y];for(let e=0;e!==i;e++)s=Ts[s^t[e]];return s})(e[at](0,h[Y]-1)))return null;if(!n){const{blockingStrategyBits:t,frameNumber:i,sampleNumber:e,samples:n,sampleRateBits:a,blockSizeBits:o,crc:c,length:u,...l}=h;s[ls](r,h,l)}return new ki(h)}constructor(t){super(t),this[R]=null,this[yt]=t[yt],this[mt]=t[mt],this[xt]=t[xt],this[Wt]=t[Wt],this[zt]=null}}class Oi extends Fs{constructor(t,s,i){super(t,s),this.Frame=_i,this.Header=ki,i(this[_])}get[_](){return"flac"}*B(t){const s=yield*this.I[is](2,0),i=s[Y]-2;for(;t<i;){if(255===s[t]){const i=s[t+1];if(248===i||249===i)break;255!==i&&t++}t++}return t}*[ys](){for(;;){const t=yield*ki[us](this.I,this.M,0);if(t){let s=Ls.get(t)[Y]+2;for(;s<=524288;){if(this.I.R||(yield*ki[us](this.I,this.M,s))){let i=yield*this.I[is](s);if(this.I.R||(i=i[at](0,s)),_i[bs](i)){const e=new _i(i,t);return this.M[ws](),this.I[es](s),this.I[rs](e),e}}s=yield*this.B(s+1)}this.I[ns](`Unable to sync FLAC frame after searching ${s} bytes.`),this.I[es](s)}else this.I[es](yield*this.B(1))}}[fs](t){return 0===t[Nt]?(this.M[ws](),this.L=t[$][at](13)):1===t[Nt]||(t[T]=Us.get(t)[nt].map((t=>{const s=ki[gs](t,this.M);if(s)return new _i(t,s,this.L);this.I[ns]("Failed to parse Ogg FLAC frame","Skipping invalid FLAC frame")})).filter((t=>!!t))),t}}class Di{static*[us](t,s,i){const e={};let h=yield*t[is](28,i);if(79!==h[0]||103!==h[1]||103!==h[2]||83!==h[3])return null;e[Jt]=h[4];if(248&h[5])return null;e[W]=!!(4&h[5]),e[N]=!!(2&h[5]),e[U]=!!(1&h[5]);const r=new qs(Ss.from(h[at](0,28))[P]);try{e[g]=r.getBigInt64(6,!0)}catch{}e[Kt]=r.getInt32(14,!0),e[Nt]=r.getInt32(18,!0),e[Lt]=r.getInt32(22,!0);const n=h[26];e[Y]=n+27,h=yield*t[is](e[Y],i),e[It]=0,e[Ft]=[],e[Ut]=Ss.from(h[at](27,e[Y]));for(let t=0,s=0;t<n;t++){const i=e[Ut][t];e[It]+=i,s+=i,255===i&&t!==n-1||(e[Ft].push(s),s=0)}return new Di(e)}constructor(t){Ls.set(this,t),this[g]=t[g],this[U]=t[U],this[N]=t[N],this[W]=t[W],this[Ft]=t[Ft],this[Nt]=t[Nt],this[Lt]=t[Lt],this[Kt]=t[Kt]}}class Bi extends Ns{static*[ds](t,s,i){const e=yield*Di[us](t,s,i);if(e){const s=Ls.get(e)[It],i=Ls.get(e)[Y],h=i+s,r=(yield*t[is](h,0))[at](0,h),n=r[at](i,h);return new Bi(e,n,r)}return null}constructor(t,s,i){super(t,s),Us.get(this)[Y]=i[Y],this[T]=[],this[rt]=i,this[g]=t[g],this[x]=t[Lt],this[O]=0,this[U]=t[U],this[N]=t[N],this[W]=t[W],this[Nt]=t[Nt],this[Qt]=0,this[Kt]=t[Kt]}}class Li extends js{constructor(t,s){super(s,t,s[kt]*s[Ct]/1e3*s[Gt])}}const Ui={0:u.slice(0,2),1:u},Fi="SILK-only",Ni="CELT-only",ji="Hybrid",Wi="narrowband",Gi="medium-band",Hi="wideband",Qi="super-wideband",Vi="fullband",Yi={0:{[z]:Fi,[b]:Wi,[kt]:10},8:{[z]:Fi,[b]:Wi,[kt]:20},16:{[z]:Fi,[b]:Wi,[kt]:40},24:{[z]:Fi,[b]:Wi,[kt]:60},32:{[z]:Fi,[b]:Gi,[kt]:10},40:{[z]:Fi,[b]:Gi,[kt]:20},48:{[z]:Fi,[b]:Gi,[kt]:40},56:{[z]:Fi,[b]:Gi,[kt]:60},64:{[z]:Fi,[b]:Hi,[kt]:10},72:{[z]:Fi,[b]:Hi,[kt]:20},80:{[z]:Fi,[b]:Hi,[kt]:40},88:{[z]:Fi,[b]:Hi,[kt]:60},96:{[z]:ji,[b]:Qi,[kt]:10},104:{[z]:ji,[b]:Qi,[kt]:20},112:{[z]:ji,[b]:Vi,[kt]:10},120:{[z]:ji,[b]:Vi,[kt]:20},128:{[z]:Ni,[b]:Wi,[kt]:2.5},136:{[z]:Ni,[b]:Wi,[kt]:5},144:{[z]:Ni,[b]:Wi,[kt]:10},152:{[z]:Ni,[b]:Wi,[kt]:20},160:{[z]:Ni,[b]:Hi,[kt]:2.5},168:{[z]:Ni,[b]:Hi,[kt]:5},176:{[z]:Ni,[b]:Hi,[kt]:10},184:{[z]:Ni,[b]:Hi,[kt]:20},192:{[z]:Ni,[b]:Qi,[kt]:2.5},200:{[z]:Ni,[b]:Qi,[kt]:5},208:{[z]:Ni,[b]:Qi,[kt]:10},216:{[z]:Ni,[b]:Qi,[kt]:20},224:{[z]:Ni,[b]:Vi,[kt]:2.5},232:{[z]:Ni,[b]:Vi,[kt]:5},240:{[z]:Ni,[b]:Vi,[kt]:10},248:{[z]:Ni,[b]:Vi,[kt]:20}};class zi extends Ys{static[gs](t,s,i){const e={};if(e[vt]=t[9],e[St]=t[18],e[Y]=0!==e[St]?21+e[vt]:19,t[Y]<e[Y])throw new Error("Out of data while inside an Ogg Page");const h=3&s[0],r=3===h?2:1,n=$s(t[at](0,e[Y]))+$s(s[at](0,r)),a=i[us](n);if(a)return new zi(a);if("OpusHead"!==n.substr(0,8))return null;if(1!==t[8])return null;e[$]=Ss.from(t[at](0,e[Y]));const o=new qs(e[$][P]);if(e[S]=16,e[st]=o.getUint16(10,!0),e[Dt]=o.getUint32(12,!0),e[Gt]=l,e[tt]=o.getInt16(16,!0),e[St]in Ui&&(e[Mt]=Ui[e[St]][e[vt]-1],!e[Mt]))return null;0!==e[St]&&(e[Yt]=t[19],e[C]=t[20],e[qt]=[...t[at](21,e[vt]+21)]);const c=Yi[248&s[0]];switch(e[z]=c[z],e[b]=c[b],e[kt]=c[kt],h){case 0:e[Ct]=1;break;case 1:case 2:e[Ct]=2;break;case 3:e[Q]=!!(128&s[1]),e[B]=!!(64&s[1]),e[Ct]=63&s[1];break;default:return null}{const{length:t,data:s,channelMappingFamily:h,...r}=e;i[ls](n,e,r)}return new zi(e)}constructor(t){super(t),this[$]=t[$],this[b]=t[b],this[St]=t[St],this[qt]=t[qt],this[C]=t[C],this[Ct]=t[Ct],this[kt]=t[kt],this[B]=t[B],this[Dt]=t[Dt],this[Q]=t[Q],this[z]=t[z],this[tt]=t[tt],this[st]=t[st],this[Yt]=t[Yt]}}class Ki extends Fs{constructor(t,s,i){super(t,s),this.Frame=Li,this.Header=zi,i(this[_]),this.U=null}get[_](){return"opus"}[fs](t){return 0===t[Nt]?(this.M[ws](),this.U=t[$]):1===t[Nt]||(t[T]=Us.get(t)[nt].map((t=>{const s=zi[gs](this.U,t,this.M);if(s)return new Li(t,s);this.I[as]("Failed to parse Ogg Opus Header","Not a valid Ogg Opus file")}))),t}}class Ji extends js{constructor(t,s,i){super(s,t,i)}}const Zi={};for(let t=0;t<8;t++)Zi[t+6]=2**(6+t);class Xi extends Ys{static[gs](t,s,i,e){if(t[Y]<30)throw new Error("Out of data while inside an Ogg Page");const h=$s(t[at](0,30)),r=s[us](h);if(r)return new Xi(r);const n={[Y]:30};if("vorbis"!==h.substr(0,7))return null;n[$]=Ss.from(t[at](0,30));const a=new qs(n[$][P]);if(n[ot]=a.getUint32(7,!0),0!==n[ot])return null;if(n[vt]=t[11],n[Mt]=u[n[vt]-1]||"application defined",n[Gt]=a.getUint32(12,!0),n[M]=a.getInt32(16,!0),n[v]=a.getInt32(20,!0),n[A]=a.getInt32(24,!0),n[wt]=Zi[(240&t[28])>>4],n[pt]=Zi[15&t[28]],n[pt]>n[wt])return null;if(1!==t[29])return null;n[S]=32,n[lt]=e,n[ut]=i;{const{length:t,data:i,version:e,vorbisSetup:r,vorbisComments:a,...o}=n;s[ls](h,n,o)}return new Xi(n)}constructor(t){super(t),this[M]=t[M],this[A]=t[A],this[v]=t[v],this[pt]=t[pt],this[wt]=t[wt],this[$]=t[$],this[ut]=t[ut],this[lt]=t[lt]}}class te extends Fs{constructor(t,s,i){super(t,s),this.Frame=Ji,i(this[_]),this.U=null,this.N=!1,this.W=null}get[_](){return ct}[fs](t){t[T]=[];for(const s of Us.get(t)[nt])if(1===s[0])this.M[ws](),this.U=t[$],this.N=!1;else if(3===s[0])this.G=s;else if(5===s[0])this.H=s,this.V=this.Y(s),this.N=!0;else if(this.N){const i=Xi[gs](this.U,this.M,this.G,this.H);i?t[T].push(new Ji(s,i,this.K(s,i))):this.I[logError]("Failed to parse Ogg Vorbis Header","Not a valid Ogg Vorbis file")}return t}K(t,s){const i=this.V.blockFlags[t[0]>>1&this.V.mask]?s[wt]:s[pt],e=null===this.W?0:(this.W+i)/4;return this.W=i,e}Y(t){const s=new Ds(t),i={count:0,blockFlags:[]};for(;1&~s.read(1););let e;for(;i.count<64&&s.position>0;){Os(s.read(8));let t=0;for(;0===s.read(8)&&t++<3;);if(4!==t){1+((126&Os(e))>>1)!==i.count&&this.I[ns]("vorbis derived mode count did not match actual mode count");break}e=s.read(7),i.blockFlags.unshift(1&e),s.position+=6,i.count++}return i.mask=(1<<Math.log2(i.count))-1,i}}class se{constructor(t,s,i){this.I=t,this.M=s,this.J=i,this.Z=new Ss,this.X=null,this.tt=null}get[_](){return this.X||""}st(t,s){this.X!==t&&(this.M[ps](),this.it=new s(this.I,this.M,this.J),this.X=t)}et({data:t}){const s=$s(t[at](0,8));switch(s){case"fishead\0":return!1;case"OpusHead":return this.st("opus",Ki),!0;case/^\x7fFLAC/.test(s)&&s:return this.st("flac",Oi),!0;case/^\x01vorbis/.test(s)&&s:return this.st(ct,te),!0;default:return!1}}ht(t){t[Nt]!==this.rt+1&&this.rt>1&&t[Nt]>1&&this.I[ns]("Unexpected gap in Ogg Page Sequence Number.",`Expected: ${this.rt+1}, Got: ${t[Nt]}`),this.rt=t[Nt]}nt(t){null===this.tt&&(this.rt=t[Nt],this.tt=this.et(t)),this.ht(t);const s=Us.get(t),i=Ls.get(s[L]);let e=0;if(s[nt]=i[Ft].map((s=>t[$][at](e,e+=s))),this.Z[Y]&&(s[nt][0]=xs(this.Z,s[nt][0]),this.Z=new Ss),255===i[Ut][i[Ut][Y]-1]&&(this.Z=xs(this.Z,s[nt].pop())),this.tt){const s=this.it[fs](t);return this.I[rs](s),s}return t}}class ie extends Fs{constructor(t,s,i){super(t,s),this.J=i,this.Frame=Bi,this.Header=Di,this.ot=new Map,this.ct=null}get[_](){const t=this.ot.get(this.ct);return t?t.codec:""}*[ys](){const t=yield*this[cs](!0);this.ct=t[Kt];let s=this.ot.get(this.ct);return s||(s=new se(this.I,this.M,this.J),this.ot.set(this.ct,s)),t[W]&&this.ot.delete(this.ct),s.nt(t)}}const ee=()=>{};const he=class{constructor(t,{onCodec:s,onCodecHeader:i,onCodecUpdate:e,enableLogging:h=!1,enableFrameCRC32:r=!0}={}){this.ut=t,this.J=s||ee,this.h=i||ee,this.S=e,this.lt=h,this.dt=r?Rs:ee,this[ps]()}get[_](){return this.it?this.it[_]:""}[ps](){this.M=new Bs(this.h,this.S),this.yt=this.ft(),this.yt.next()}*flush(){this.R=!0;for(let t=this.yt.next();t.value;t=this.yt.next())yield t.value;this.R=!1,this[ps]()}*parseChunk(t){for(let s=this.yt.next(t);s.value;s=this.yt.next())yield s.value}parseAll(t){return[...this.parseChunk(t),...this.flush()]}*ft(){if(this.ut.match(/aac/))this.it=new Ei(this,this.M,this.J);else if(this.ut.match(/mpeg/))this.it=new wi(this,this.M,this.J);else if(this.ut.match(/flac/))this.it=new Oi(this,this.M,this.J);else{if(!this.ut.match(/ogg/))throw new Error(`Unsupported Codec ${mimeType}`);this.it=new ie(this,this.M,this.J)}for(this.wt=0,this.gt=0,this.bt=0,this.St=0,this.qt=0,this.Mt=void 0,this.At=new Uint8Array(0);;){const t=yield*this.it[ys]();t&&(yield t)}}*[is](t=0,s=0){let i;for(;this.At[Y]<=t+s;){if(i=yield,this.R)return this.At[at](s);i&&(this.bt+=i[Y],this.At=xs(this.At,i))}return this.At[at](s)}[es](t){this.gt+=t,this.At=this.At[at](t)}[hs](t){this.Mt=t[L][Gt],t[L][q]=t[O]>0?8*Math.round(t[$][Y]/t[O]):0,t[xt]=this.wt++,t[Xt]=this.St,t[ss]=this.qt,t[ts]=this.qt/this.Mt*1e3,t[x]=this.dt(t[$]),this.M[ms](t[L][q],t[ts]),this.St+=t[$][Y],this.qt+=t[Qt]}[rs](t){t[T]?(t[T].forEach((s=>{t[O]+=s[O],t[Qt]+=s[Qt],this[hs](s)})),t[ss]=this.qt,t[ts]=this.qt/this.Mt*1e3||0,t[Xt]=this.St):this[hs](t)}vt(t,s){if(this.lt){const i=[`${_}: ${this[_]}`,`inputMimeType: ${this.ut}`,`readPosition: ${this.gt}`,`totalBytesIn: ${this.bt}`,`${Xt}: ${this.St}`],e=Math.max(...i.map((t=>t[Y])));s.push(`--stats--${"-".repeat(e-9)}`,...i,"-".repeat(e)),t("codec-parser",s.reduce(((t,s)=>t+"\n "+s),""))}}[ns](...t){this.vt(console.warn,t)}[as](...t){this.vt(console.error,t)}},re=g,ne=T,ae=$,oe=L,ce=W,ue=ut,le=lt,de=Qt}},h={};function r(t){var s=h[t];if(void 0!==s)return s.exports;var i=h[t]={exports:{}};return e[t](i,i.exports,r),i.exports}r.m=e,t=[],r.O=(s,i,e,h)=>{if(!i){var n=1/0;for(u=0;u<t.length;u++){for(var[i,e,h]=t[u],a=!0,o=0;o<i.length;o++)(!1&h||n>=h)&&Object.keys(r.O).every((t=>r.O[t](i[o])))?i.splice(o--,1):(a=!1,h<n&&(n=h));if(a){t.splice(u--,1);var c=e();void 0!==c&&(s=c)}}return s}h=h||0;for(var u=t.length;u>0&&t[u-1][2]>h;u--)t[u]=t[u-1];t[u]=[i,e,h]},r.F={},r.E=t=>{Object.keys(r.F).map((s=>{r.F[s](t)}))},r.d=(t,s)=>{for(var i in s)r.o(s,i)&&!r.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:s[i]})},r.f={},r.e=t=>Promise.all(Object.keys(r.f).reduce(((s,i)=>(r.f[i](t,s),s)),[])),r.u=t=>385===t?"icecast-metadata-player-1.17.3.common.min.js":"icecast-metadata-player-1.17.3."+{88:"mpeg",398:"vorbis",694:"opus",731:"synaudio",762:"mediasource",993:"flac"}[t]+".min.js",r.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(t){if("object"==typeof window)return window}}(),r.o=(t,s)=>Object.prototype.hasOwnProperty.call(t,s),s={},i="IcecastMetadataPlayer:",r.l=(t,e,h,n)=>{if(s[t])s[t].push(e);else{var a,o;if(void 0!==h)for(var c=document.getElementsByTagName("script"),u=0;u<c.length;u++){var l=c[u];if(l.getAttribute("src")==t||l.getAttribute("data-webpack")==i+h){a=l;break}}a||(o=!0,(a=document.createElement("script")).charset="utf-8",a.timeout=120,r.nc&&a.setAttribute("nonce",r.nc),a.setAttribute("data-webpack",i+h),a.src=t),s[t]=[e];var d=(i,e)=>{a.onerror=a.onload=null,clearTimeout(y);var h=s[t];if(delete s[t],a.parentNode&&a.parentNode.removeChild(a),h&&h.forEach((t=>t(e))),i)return i(e)},y=setTimeout(d.bind(null,void 0,{type:"timeout",target:a}),12e4);a.onerror=d.bind(null,a.onerror),a.onload=d.bind(null,a.onload),o&&document.head.appendChild(a)}},r.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"Pt",{value:!0})},(()=>{var t;r.g.importScripts&&(t=r.g.location+"");var s=r.g.document;if(!t&&s&&(s.currentScript&&(t=s.currentScript.src),!t)){var i=s.getElementsByTagName("script");if(i.length)for(var e=i.length-1;e>-1&&(!t||!/^http(s?):/.test(t));)t=i[e--].src}if(!t)throw new Error("Automatic publicPath is not supported in this browser");t=t.replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),r.p=t})(),(()=>{var t={792:0};r.f.j=(s,i)=>{var e=r.o(t,s)?t[s]:void 0;if(0!==e)if(e)i.push(e[2]);else{var h=new Promise(((i,h)=>e=t[s]=[i,h]));i.push(e[2]=h);var n=r.p+r.u(s),a=new Error;r.l(n,(i=>{if(r.o(t,s)&&(0!==(e=t[s])&&(t[s]=void 0),e)){var h=i&&("load"===i.type?"missing":i.type),n=i&&i.target&&i.target.src;a.message="Loading chunk "+s+" failed.\n("+h+": "+n+")",a.name="ChunkLoadError",a.type=h,a.request=n,e[1](a)}}),"chunk-"+s,s)}},r.F.j=s=>{if(!r.o(t,s)||void 0===t[s]){t[s]=null;var i=document.createElement("link");r.nc&&i.setAttribute("nonce",r.nc),i.rel="prefetch",i.as="script",i.href=r.p+r.u(s),document.head.appendChild(i)}},r.O.j=s=>0===t[s];var s=(s,i)=>{var e,h,[n,a,o]=i,c=0;if(n.some((s=>0!==t[s]))){for(e in a)r.o(a,e)&&(r.m[e]=a[e]);if(o)var u=o(r)}for(s&&s(i);c<n.length;c++)h=n[c],r.o(t,h)&&t[h]&&t[h][0](),t[h]=0;return r.O(u)},i=self.webpackChunkIcecastMetadataPlayer=self.webpackChunkIcecastMetadataPlayer||[];i.forEach(s.bind(null,0)),i.push=s.bind(null,i.push.bind(i))})(),r.O(0,[792],(()=>{r.E(731),r.E(762)}),5);var n={};(()=>{r.d(n,{default:()=>gt});const t=()=>{},s=new WeakMap,i={LOADING:"loading",PLAYING:"playing",STOPPING:"stopping",STOPPED:"stopped",RETRYING:"retrying",SWITCHING:"switching"},e={BUFFER:"buffer",PLAY:"play",PLAY_READY:"playready",LOAD:"load",STREAM_START:"streamstart",STREAM:"stream",STREAM_END:"streamend",METADATA:"metadata",METADATA_ENQUEUE:"metadataenqueue",CODEC_UPDATE:"codecupdate",STOP:"stop",RETRY:"retry",RETRY_TIMEOUT:"retrytimeout",SWITCH:"switch",WARN:"warn",ERROR:"error",PLAYBACK_ERROR:"playbackerror"},h=Symbol(),a=Symbol(),o=Symbol(),c=Symbol(),u=Symbol(),l=Symbol(),d=Symbol(),y=Symbol(),f=Symbol(),m=Symbol(),p=Symbol(),w=Symbol(),g=Symbol(),b=Symbol(),S=Symbol(),q=Symbol(),M=Symbol(),A=Symbol(),v=Symbol(),P=Symbol(),E=Symbol(),_=Symbol(),T=Symbol(),C=Symbol(),I=Symbol(),R=Symbol(),x=Symbol(),$=Symbol("synced"),k=Symbol("syncing"),O=Symbol("pcm_synced"),D=Symbol("not_synced"),B=t=>{const s=new Uint8Array(t.reduce(((t,s)=>t+s.length),0));return t.reduce(((t,i)=>(s.set(i,t),t+i.length)),0),s};class L{constructor(){this.Et=[]}hasEventListener(t,s){return this.Et.some((i=>i.type===t&&i.listener===s))}addEventListener(t,s,i={}){return this.hasEventListener(t,s)||this.Et.push({type:t,listener:s,options:i}),this}removeEventListener(t,s){const i=this.Et.findIndex((i=>i.type===t&&i.listener===s));return i>=0&&this.Et.splice(i,1),this}removeEventListeners(){return this.Et=[],this}dispatchEvent(t){return this.Et.filter((s=>s.type===t.type)).forEach((s=>{const{type:i,listener:e,options:{once:h}}=s;e.call(this,t),!0===h&&this.removeEventListener(i,e)})),this}}class U{constructor(){this._t=0,this.Tt=0,this.Ct=0,this.It=0,this.Rt=0,this.xt=0,this.$t=0}get stats(){return{totalBytesRead:this._t,streamBytesRead:this.Tt,metadataLengthBytesRead:this.Ct,metadataBytesRead:this.It,currentBytesRemaining:this.Rt,currentStreamBytesRemaining:this.xt,currentMetadataBytesRemaining:this.$t}}set currentStreamBytesRemaining(t){this.xt+=t}set currentMetadataBytesRemaining(t){this.$t=t}addBytes(t){this._t+=t,this.Rt-=t}addStreamBytes(t){this.Tt+=t,this.xt-=t}addMetadataLengthBytes(t){this.Ct+=t}addMetadataBytes(t){this.It+=t,this.$t-=t}addCurrentBytesRemaining(t){this.Rt+=t}}const F=()=>{};class N{constructor(t){this.kt=0,this.Ot=0,this.Dt=new Uint8Array(0),this.Bt=[],this.Lt=0,this.Ut=new U,this.Ft=t.onStream||F,this.Nt=t.onMetadata||F,this.jt=t.onMetadataFailed||F,this.Wt=t.onError||F,this.lt=t.enableLogging||!1,this.Gt=Promise.resolve(),this.Ht=Promise.resolve(),this.yt=this.Qt(),this.yt.next()}*Qt(){for(this.kt=1/0;;)this.Vt(yield*this.Yt()),yield*this.zt()}static Kt(...t){const s=t.reduce(((t,s)=>t+s.length),0);return this.Jt(t,s)}static Jt(t,s){const i=new Uint8Array(s);return t.reduce(((t,s)=>(i.set(s,t),t+s.length)),0),i}*iterator(t){for(let s=this.yt.next(t);s.value;s=this.yt.next())yield s.value}readAll(t){for(let s=this.yt.next(t);s.value;s=this.yt.next());}async*asyncIterator(t){for(let s=this.yt.next(t);s.value;s=this.yt.next())await this.Gt,await this.Ht,yield s.value}async asyncReadAll(t){for(let s=this.yt.next(t);s.value;s=this.yt.next())await this.Gt,await this.Ht}Zt(...t){this.lt&&console.warn("icecast-metadata-js",t.reduce(((t,s)=>t+"\n "+s),"")),this.Wt(...t)}Vt(t){this.Bt.push(t),this.Lt+=t.length}*zt(){if(this.Bt.length){const t=N.Jt(this.Bt,this.Lt);this.Bt=[],this.Lt=0,this.Ut.addStreamBytes(t.length);const s={stream:t,stats:this.Ut.stats};this.Gt=this.Ft(s),yield s}}*Xt(t){yield*this.zt();const s={metadata:t,stats:this.Ut.stats};this.Ht=this.Nt(s),yield s}*Yt(t=0){for(this.Ot===this.Dt.length&&(this.Dt=yield*this.ts(),this.Ot=0);this.Dt.length-this.Ot<t;)this.Dt=N.Kt(this.Dt,yield*this.ts());const s=this.Dt.subarray(this.Ot,(t||this.kt)+this.Ot);return this.Ut.addBytes(s.length),this.kt=s.length<this.kt?this.kt-s.length:0,this.Ot+=s.length,s}*ts(){let t;yield*this.zt();do{t=yield}while(!t||0===t.length);return this.Ut.addCurrentBytesRemaining(t.length),t}}class j extends N{constructor({icyMetaInt:t,icyDetectionTimeout:s=2e3,icyCharacterEncoding:i="utf-8",...e}){super(e),this.ss=new globalThis.TextDecoder(i),this.es=t,this.hs=s,this.yt=this.rs(),this.yt.next()}*rs(){if(yield*this.ns())for(;;)this.kt=this.es,yield*this.os(),yield*this.cs(),this.kt&&(yield*this.us());this.kt=1/0,yield*this.os()}static parseIcyMetadata(t){const s=/(?<key>[^\0]+?)='(?<val>[^\0]*?)(;$|';|'$|$)/,i={};for(const e of t.match(new RegExp(s,"g"))||[]){const t=e.match(s);t&&(i[t.groups.key]=t.groups.val)}return i}get icyMetaInt(){return this.es}*ns(){if(this.es>0)return!0;if(!this.hs)return!1;this.Zt("Passed in Icy-MetaInt is invalid. Attempting to detect ICY Metadata.","See https://github.com/eshaz/icecast-metadata-js for information on how to properly request ICY Metadata.");const t=[null,83,116,114,101,97,109,84,105,116,108,101,61],s=Date.now();let i=0;for(;s+this.hs>Date.now();){this.Dt=N.Kt(this.Dt,yield*this.ts());t:for(;i<this.Dt.length-t.length;){for(let s=1;s<t.length;s++)if(this.Dt[s+i]!==t[s]){i++;continue t}return this.Zt(`Found ICY Metadata! Setting Icy-MetaInt to ${i}.`),this.es=i,!0}}return this.Zt("ICY Metadata not detected, but continuing anyway. Audio errors will occur if there is ICY metadata.",`Searched ${this.Dt.length} bytes for ${(Date.now()-s)/1e3} seconds.`,"Try increasing the `icyDetectionTimeout` value if ICY metadata is present in the stream."),this.jt("icy"),!1}*os(){for(this.Ut.currentStreamBytesRemaining=this.kt;this.kt;)this.Vt(yield*super.Yt())}*cs(){this.kt=1;do{this.kt=16*(yield*this.Yt())[0]}while(1===this.kt);this.Ut.addMetadataLengthBytes(1)}*us(){this.Ut.currentMetadataBytesRemaining=this.kt;const t=yield*this.Yt(this.kt);this.Ut.addMetadataBytes(t.length),yield*this.Xt(j.parseIcyMetadata(this.ss.decode(t)))}}class W extends N{constructor(t){super(t),this.ss=new globalThis.TextDecoder("utf-8"),this.yt=this.ls(),this.yt.next(),this.ds=!1}*ls(){if(yield*this.ys()){const t=yield*this.fs();if(t)for(;yield*this.ys();)this.ds||(yield*this.us(t)),yield*this.os()}this.kt=1/0,yield*this.os()}ps(t,s=0){return new DataView(Uint8Array.from([...t.subarray(s,s+4)]).buffer).getUint32(0,!0)}ws(t,s){return String.fromCharCode(...s).match(t)}*ys(){let t=[];for(;t.length<=65307;){const s=yield*super.Yt(6);if(79===s[0]&&103===s[1]&&103===s[2]&&83===s[3]&&!(248&s[5])){this.ds=1&s[5],this.Ot-=6,this.kt+=6,this.Ut._t-=6,this.Ut.Rt+=6;break}t.push(s[0]),this.Ot-=5,this.Ut._t-=5,this.Ut.Rt+=5}if(t.length&&this.Vt(Uint8Array.from(t)),t.length>65307)return this.Zt("This stream is not an Ogg stream. No Ogg metadata will be returned.","See https://github.com/eshaz/icecast-metadata-js for information on Ogg metadata."),this.jt("ogg"),!1;const s=yield*this.Yt(27),i=yield*this.Yt(s[26]);return this.kt=i.reduce(((t,s)=>t+s),0),!0}*fs(){const t=yield*this.Yt(8);return yield*this.os(),this.ws(/\x7fFLAC/,t.subarray(0,5))?{regex:/^[\x84|\x04]/,length:4}:this.ws(/OpusHead/,t.subarray(0,8))?{regex:/OpusTags/,length:8}:this.ws(/\x01vorbis/,t.subarray(0,7))?{regex:/\x03vorbis/,length:7}:void 0}*us({regex:t,length:s}){this.ws(t,yield*this.Yt(s))&&(yield*this.Xt(yield*this.gs()))}*os(){for(;this.kt;)yield*this.Yt()}*Yt(t){const s=yield*super.Yt(t);return this.Vt(s),s}*ts(){const t=yield*super.ts();return this.Ut.currentStreamBytesRemaining=t.length,t}*gs(){const t=this.ps(yield*this.Yt(4));this.Ut.addMetadataBytes(4);const s=this.ss.decode(yield*this.Yt(t));this.Ut.addMetadataBytes(t);const i=this.ps(yield*this.Yt(4));this.Ut.addMetadataBytes(4);const e=[];for(let t=0;t<i;t++){const t=yield*this.Yt(4);this.Ut.addMetadataBytes(4),e.push(yield*this.Yt(this.ps(t))),this.Ut.addMetadataBytes(e[e.length-1].length)}return this.Ut.currentMetadataBytesRemaining=0,e.reduce(((t,s)=>{const i=s.indexOf(61),e=String.fromCharCode(...s.subarray(0,i)).toUpperCase(),h=this.ss.decode(s.subarray(i+1));return t[e]=t[e]?`${t[e]}; ${h}`:h,t}),{VENDOR_STRING:s})}}class G{constructor(t){const{onStream:s,...i}=t;this.bs=new W(t),this.Ss=new j(i)}get icyMetaInt(){return this.Ss.icyMetaInt}*iterator(t){for(const s of this.Ss.iterator(t))s.stream?yield*this.bs.iterator(s.stream):yield s}readAll(t){for(const s of this.Ss.iterator(t))s.stream&&this.bs.readAll(s.stream)}async*asyncIterator(t){for await(const s of this.Ss.asyncIterator(t))if(s.stream)for await(const t of this.bs.asyncIterator(s.stream))yield t;else yield s}async asyncReadAll(t){for await(const s of this.Ss.iterator(t))s.stream&&await this.bs.asyncReadAll(s.stream)}}class H{constructor({metadataTypes:t=["icy"],...s}={}){const i=t.includes("icy"),e=t.includes("ogg");this.qs=i&&e?new G(s):e?new W(s):i?new j(s):new N(s)}static parseIcyMetadata(t){return j.parseIcyMetadata(t)}get icyMetaInt(){return this.qs.icyMetaInt}*iterator(t){yield*this.qs.iterator(t)}readAll(t){this.qs.readAll(t)}async*asyncIterator(t){return yield*this.qs.asyncIterator(t)}async asyncReadAll(t){return this.qs.asyncReadAll(t)}}const Q=()=>{};class V{constructor(t,{onStream:s=Q,...i}){let e;this.Ms=new ReadableStream({async start(h){e=new H({icyMetaInt:parseInt(t.headers.get("Icy-MetaInt")),...i,onStream:async t=>(h.enqueue(t.stream),s(t))});for await(const s of V.asyncIterator(t.body))await e.asyncReadAll(s);h.close()}}),this.As=e}get icyMetaInt(){return this.As.icyMetaInt}get readableStream(){return this.Ms}async startReading(){try{for await(const t of V.asyncIterator(this.Ms));}catch(t){if("AbortError"!==t.name)throw t}}static asyncIterator(t){const s=t.getReader();return{[Symbol.asyncIterator]:()=>({next:()=>s.read()})}}}const Y=()=>{};class z{constructor({icyBr:t,onMetadataUpdate:s=Y,onMetadataEnqueue:i=Y,paused:e=!1}){this.vs=t,this.Ps=s,this.Es=i,this._s=e,this.Ts=e,this.Cs=!0,this.Is=[],this.Rs=[]}get metadataQueue(){return this.Rs.map((({xs:t,...s})=>s))}addMetadata({metadata:t,stats:s},i,e=0){const h={metadata:t,timestampOffset:i,timestamp:e+=s?this.getTimeByBytes(s.currentStreamPosition):0};this.Ts?this.Is.push(h):this.$s(h)}getTimeByBytes(t){return this.vs?t/(125*this.vs):0}startQueue(t){this.Ts&&(this.Is.forEach((s=>{void 0!==t&&(s.timestamp=t),(void 0===t||s.timestampOffset>=s.timestamp)&&this.$s(s)})),this.Is=[],this.Ts=!1)}purgeMetadataQueue(){this.Rs.forEach((t=>clearTimeout(t.xs))),this.Rs=[],this.Is=[],this.Ts=this._s,this.Cs=!0}$s(t){this.Rs.push(t),this.Es(t.metadata,t.timestampOffset,t.timestamp),this.Cs?(this.ks(),this.Cs=!1):t.xs=setTimeout((()=>{this.ks()}),1e3*(t.timestampOffset-t.timestamp))}ks(){if(this.Rs.length){const{metadata:t,timestampOffset:s,timestamp:i}=this.Rs.shift();this.Ps(t,s,i)}}}var K=r(317);let J;const Z=new Worker(URL.createObjectURL(new Blob(["self.onmessage = () => self.postMessage(!!self.Worker)"],{type:"text/javascript"})));Z.onmessage=t=>{J=t.data,Z.terminate()},Z.postMessage(null);class X{constructor(t,s){this.CRC_DURATION=3e5,this.PCM_DURATION=6e4,this.As=t,this.Os=s,this.initSync(),this.initQueue()}initSync(){clearTimeout(this.Ds),this.Ds=null,this.Bs=null,this.Ls=!0,this.Us=[],this.Fs=0,this.Ns=null,this.js=null,this.Ws=null}initQueue(){this.Gs=0,this.Hs=0,this.Qs=0,this.Vs=[],this.Ys=0,this.zs={},this.Ks=[],this.Js=0}get buffered(){return this.Hs/this.Qs-this.Os.currentTime||0}add(t){const{crc32:s,duration:i,samples:e}=t;this.Hs+=e,this.Qs=t.header.sampleRate,this.Vs.push({crc32:s,duration:i}),this.Ys+=i;let h=this.zs[s];if(h||(h=[],this.zs[s]=h),h.push(this.Gs++),this.Ys>=this.CRC_DURATION){const{crc32:t,duration:s}=this.Vs.shift();this.Ys-=s;const i=this.zs[t];i.shift(),i.length||delete this.zs[t]}this.Ks.push(t),this.Js+=i,this.Js>=this.PCM_DURATION&&(this.Js-=this.Ks.shift().duration)}addAll(t){t.forEach((t=>this.add(t)))}Zs(t){for(const s of t)this.Fs+=s.duration,this.Us.push(s)}async sync(s){if(null===this.Ds){const s=this.buffered;this.Xs=t,this.Ds=setTimeout((()=>{this.Bs=`Buffer underrun after syncing for ${s.toFixed(2)} seconds.`,this.Xs(this.Bs)}),1e3*s)}return this.Zs(s),new Promise((async(t,s)=>{let i;null!==this.Bs?s(this.Bs):this.Xs=s,this.Ls&&(i=this.ti()),i||(this.Ls=!1,i=await this.si()),i?t(i):s("Old and new request do not match.")})).catch((t=>{this.As.state!==i.STOPPING&&this.As.state!==i.STOPPED&&this.As[P](e.WARN,`Reconnected successfully after ${this.As.state}.`,"Unable to sync old and new request.",t);const s=this.Us;return this.initSync(),this.initQueue(),[s,D]})).then((t=>([$,O].includes(t[1])&&this.initSync(),t)))}ti(){if(!this.Us.length)return[[],k];const t=this.Us[0].crc32,s=this.zs[t];let i,h,r;if(s){t:for(const t of s){r=t-(this.Gs-this.Vs.length);for(let t=0;t<this.Us.length&&r+t<this.Vs.length;t++)if(this.Vs[r+t].crc32!==this.Us[t].crc32)continue t;h=r+this.Us.length<=this.Vs.length,i=!0;break}if(h)return[[],k];if(i){const t=this.Vs.length-r;return this.As[P](e.WARN,`Reconnected successfully after ${this.As.state}.`,`Found ${t} frames (${(this.Vs.slice(r).reduce(((t,{duration:s})=>t+s),0)/1e3).toFixed(3)} seconds) of overlapping audio data in new request.`,"Synchronized old and new request."),[this.Us.slice(t),$]}}}async si(){try{const t=1,s=16,i=(t,s)=>t/s;if(!this.Ns){let h;try{h=(await r.e(731).then(r.bind(r,875))).default}catch(t){return void this.As[P](e.WARN,"Failed to synchronize old and new stream","Missing `synaudio` dependency.")}const[n,a,o]=await this.ii(),c=o*t;if(a.samplesDecoded<=c)return[[],k];const u=new h({correlationSampleSize:c,initialGranularity:s});this.Ns=await(J?u.syncWorkerConcurrent(n,a,Math.max(navigator.hardwareConcurrency-1,1)):u.syncWorker(n,a)),this.Ns.offsetFromEnd=i(n.samplesDecoded-this.Ns.sampleOffset,o)}const{correlation:h,offsetFromEnd:n}=this.Ns;let a=1e3*(this.buffered-n);if(-a>this.Fs)return[[],k];const o=0;if(a<0){let t=0;for(let s=0;t<this.Us.length-o&&s>a;t++)s-=this.Us[t].duration;this.Us=this.Us.slice(t-o)}else for(let t=0;t<o&&t<this.Us.length;t++)a-=this.Us[t].duration;return this.As[P](e.WARN,`Reconnected successfully after ${this.As.state}.`,`Synchronized old and new request with ${(Math.round(1e4*h)/100).toFixed(2)}% confidence.`),this.initQueue(),[this.Us,O,a]}catch{}}async ii(){const t=(t,s)=>{let i=t.length-1;for(let e=0;e<s&&i>0;i--)e+=t[i].duration;return this.As[u].decodeAudioData(B(t.slice(i).map((({data:t})=>t))).buffer)};[this.js,this.Ws]=await Promise.all([this.js?this.js:t(this.Ks,2e3*this.buffered),t(this.Us,1/0)]);const s=t=>{const s={channelData:[],samplesDecoded:t.length};for(let i=0;i<t.numberOfChannels;i++)s.channelData.push(Float32Array.from(t.getChannelData(i)));return s};return[s(this.js),s(this.Ws),this.js.sampleRate]}}class tt{constructor(t,i,e,h,r){this.As=t,this.ei=i,this.ut=e,this.X=h,this.hi=r;const n=s.get(this.As);this.ri=n[l],this.ni=n[d],this.ai=0,this.oi=0,this.ci=()=>{this.syncState=D}}static parseMimeType(t){return t.match(/^(?:application\/|audio\/|)(?<mime>[a-zA-Z]+)(?:$|;[ ]*codecs=(?:\'|\")(?<codecs>[a-zA-Z,]+)(?:\'|\"))/)}static canPlayType(t,s,i){const e=tt.parseMimeType(s),h=s=>s.reduce(((s,i)=>{if(""===s)return"";const e=t(i);return e?"maybe"===e||"maybe"===s?"maybe":!0===e||"probably"===e?"probably":void 0:""}),null);if(e){const{mime:t,codecs:r}=e.groups,n=i&&i[t];if(!n||Array.isArray(n))return h(n||[s])||h([`audio/${t}`]);if("object"==typeof n){if(r){const t=r.split(",");return t.length>1?"":n[t[0]]?h(n[t[0]]):""}return"maybe"}}return""}enablePlayButton(t){this.ri.removeAttribute("src"),this.ri.srcObject=null,t.includes("mediasource")?this.ri.src=URL.createObjectURL(new MediaSource):t.includes("webaudio")?(this.ui=new MediaStream,this.ri.srcObject=this.ui):t.includes("html5")&&(this.ri.src="data:audio/mpeg;base64,//sQxAAABFgC/SCEYACCgB9AAAAAppppVCAHBAEIgBByw9WD5+J8ufwxiDEDsMfE+D4fwG/RUGCx6VO4awVxV3qDtQNPiXKnZUNSwKuUDR6IgaeoGg7Fg6pMQU1FMy4xMDCqqqqqqqr/+xLEB4PAAAGkAAAAIAAANIAAAASqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqo=",this.ri.loop=!0)}get syncStateUpdate(){return this.li}get syncState(){return this.di}set syncState(t){this.di=t,this.yi&&this.yi(t),this.li=new Promise((t=>{this.yi=t}))}get isSupported(){return!1}get isAudioPlayer(){return!1}get metadataTimestamp(){return 0}get currentTime(){return 0}get waiting(){return Promise.resolve()}get icecastMetadataQueue(){return this.fi}set icecastMetadataQueue(t){this.fi=t}get codecUpdateQueue(){return this.mi}set codecUpdateQueue(t){this.mi=t}get metadataQueue(){return this.fi?this.fi.metadataQueue:[]}pi(){this.fi.startQueue(this.wi),this.mi.startQueue(this.wi)}async gi(){this.syncState=$,this.syncFrames=[],this.syncDelay=null,this.bi=new X(this.As,this)}async start(t){let s;this.wi=t,[e.RETRY,e.SWITCH].forEach((t=>this.As.addEventListener(t,this.ci)));const h=new Promise((t=>{s=t,[i.PLAYING,i.STOPPING].forEach((t=>this.As.addEventListener(t,s,{once:!0})))})).finally((()=>{[i.PLAYING,i.STOPPING].forEach((t=>this.As.removeEventListener(t,s)))}));await h}async end(){[e.RETRY,e.SWITCH].forEach((t=>this.As.removeEventListener(t,this.ci))),this.fi.purgeMetadataQueue(),this.mi.purgeMetadataQueue()}onStream(t){return t}onMetadata(t){this.fi.addMetadata(t,this.metadataTimestamp,this.currentTime)}onCodecUpdate(t,s){const i=this.currentTime;s<i&&(this.oi+=this.ai),this.ai=s,this.mi.addMetadata({metadata:t},(s+this.oi)/1e3,i)}}class st extends tt{constructor(t,s){super(t,s),this.ri.crossOrigin="anonymous",this.ri.loop=!1,this.ri.preload="none",this.As.addEventListener(e.STREAM_START,(()=>{this.Si||this.end()})),this.gi()}static canPlayType(t){return st.isSupported?super.canPlayType((t=>(new Audio).canPlayType(t)),t):""}static get isSupported(){return Boolean(window.Audio)}static get name(){return"html5"}get isAudioPlayer(){return!0}get metadataTimestamp(){return this.qi?(this.qi.totalDuration+this.Mi)/1e3:0}get currentTime(){return this.Ai&&(performance.now()-this.Ai)/1e3}get waiting(){return new Promise((t=>{this.ri.addEventListener("waiting",t,{once:!0})}))}async gi(){super.gi(),this.qi=null,this.Ai=0,this.Mi=0,this.Si=!1}async start(t){const s=super.start(t);this.Pi=performance.now(),this.ri.src=null,this.ri.srcObject=null,this.ri.src=this.ei,this.As.state!==i.STOPPING&&this.As.state!==i.STOPPED&&(this.ri.addEventListener("playing",(()=>{this.Ai=performance.now(),this.Mi=performance.now()-this.Pi,this.pi(),this.As[P](e.PLAY)}),{once:!0}),this.As[P](e.PLAY_READY),this.Si=!0),await s}async end(){super.end(),this.ri.src=null,this.ri.srcObject=null,this.gi()}onStream(t){this.qi=t[t.length-1]||this.qi,this.syncState===D&&(this.syncState=D)}}class it extends tt{constructor(t,s,i,e,h){super(t,s,i,e,h),this.Ei=r.e(762).then(r.bind(r,448)),this.gi()}static canPlayType(t){return it.isSupported?MediaSource.isTypeSupported(t)?"probably":super.canPlayType(MediaSource.isTypeSupported,t,{mpeg:['audio/mp4;codecs="mp3"'],aac:['audio/mp4;codecs="mp4a.40.2"'],aacp:['audio/mp4;codecs="mp4a.40.2"'],flac:['audio/mp4;codecs="flac"'],ogg:{flac:['audio/mp4;codecs="flac"'],opus:['audio/mp4;codecs="opus"','audio/webm;codecs="opus"'],vorbis:['audio/webm;codecs="vorbis"']}}):""}static get isSupported(){return Boolean(window.MediaSource)}static get name(){return"mediasource"}get isAudioPlayer(){return!0}get metadataTimestamp(){return this._i&&this._i.sourceBuffers.length&&Math.max(this._i.sourceBuffers[0].timestampOffset,this._i.sourceBuffers[0].buffered.length?this._i.sourceBuffers[0].buffered.end(0):0)||0}get currentTime(){return this.ri.currentTime}get waiting(){return new Promise((t=>{this.ri.addEventListener("waiting",t,{once:!0})}))}async gi(){super.gi(),this.Ti=[],this.Si=!1,this.Ci=!1,this.Ii=new Promise((t=>{this.Ri=t})),this.xi=new Promise((t=>{this.$i=t})),this.ki=this.Oi(this.ut,this.X),await this.xi}async start(t){const s=super.start(t);await this.Ii,await this.Di(),await s}async end(){super.end(),await this.gi()}async onStream(t){if((t=t.flatMap((t=>t.codecFrames?t.codecFrames.map((s=>(s.isLastPage=t.isLastPage,s))):t))).length){switch(this.syncState){case D:this.bi.initSync(),this.syncState=k;case k:[this.syncFrames,this.syncState,this.syncDelay]=await this.bi.sync(t),t=this.syncFrames}switch(this.syncState){case O:break;case $:await this.xi,await this.ki(t),this.bi.addAll(t)}}}Oi(t,s){return MediaSource.isTypeSupported(t)?(this.Bi(t),async t=>this.Li(B(t.map((t=>t.data))))):(this.hi.then((i=>this.Ui(t,s,i.channels))).then((()=>{this.Bi(this.Fi.mimeType)})),t.match(/ogg/)?async i=>{let e=[];for await(const h of i){if(this.Ci!==h.isLastPage)if(h.isLastPage)this.Ci=!0;else{await this.Li(B(e)),e=[];const i=await this.hi;await this.Ui(t,s,i.channels),this.Ci=!1}e.push(...this.Fi.iterator([h]))}await this.Li(B(e))}:async t=>this.Li(B([...this.Fi.iterator(t)])))}async Ui(t,s,i){this.Fi=new(await this.Ei).default(t,{codec:s,preferredContainer:i>2?"webm":"fmp4"}),MediaSource.isTypeSupported(this.Fi.mimeType)||this.As[P](e.PLAYBACK_ERROR,`Media Source Extensions API in your browser does not support ${t} or ${this.Fi.mimeType}.See: https://caniuse.com/mediasource and https://developer.mozilla.org/en-US/docs/Web/API/Media_Source_Extensions_API`)}Bi(t){this._i=new MediaSource,this.Ri(),this._i.addEventListener("sourceopen",(()=>{this.As.state!==i.STOPPED&&this.As.state!==i.STOPPING&&(this._i.addSourceBuffer(t).mode="sequence"),this.Ni=0,this.$i()}),{once:!0})}async Di(){this.ri.loop=!1,this.ri.src=URL.createObjectURL(this._i),await this.xi}async ji(){return new Promise((t=>{const s=this._i.sourceBuffers[0];s.updating?s.addEventListener("updateend",t,{once:!0}):t()}))}async Li(t){if(this.As[P](e.STREAM,t),this._i.sourceBuffers.length||this.As[P](e.WARN,"Attempting to append audio, but MediaSource has not been or is no longer initialized","Please be sure that `detachAudioElement()` was called and awaited before reusing the element with a new IcecastMetadataPlayer instance"),this.As.state!==i.STOPPING&&this._i.sourceBuffers.length){this.Ti.push(t);try{for(;this.Ti.length;)this._i.sourceBuffers[0].appendBuffer(this.Ti.shift()),await this.ji()}catch(t){if("QuotaExceededError"!==t.name)throw t}this.Si||(this.ni<=this.metadataTimestamp?(this.ri.addEventListener("playing",(()=>{this.pi(),this.As[P](e.PLAY)}),{once:!0}),this.As[P](e.PLAY_READY),this.Si=!0):this.As[P](e.BUFFER,this.metadataTimestamp)),this.ri.currentTime>5+this.ni&&this.Ni+5e3<performance.now()&&(this.Ni=performance.now(),this._i.sourceBuffers[0].remove(0,this.ri.currentTime-5+this.ni),await this.ji())}}}class et extends tt{constructor(t,s,i,e,h){super(t,s,i,e,h),this.Wi=t[u],this.gi()}static canPlayType(t){return et.isSupported?super.canPlayType((t=>'audio/ogg;codecs="opus"'===t||'audio/ogg;codecs="flac"'===t||'audio/ogg;codecs="vorbis"'===t||"audio/mpeg"===t||"audio/flac"===t),t,{flac:["audio/flac"],mpeg:["audio/mpeg"],ogg:{flac:['audio/ogg;codecs="flac"'],opus:['audio/ogg;codecs="opus"'],vorbis:['audio/ogg;codecs="vorbis"']}}):""}static get isSupported(){return Boolean(window.WebAssembly&&(window.AudioContext||window.webkitAudioContext)&&window.MediaStream)}static get name(){return"webaudio"}get isAudioPlayer(){return!0}get metadataTimestamp(){return this.Gi/1e3}get currentTime(){return(performance.now()-this.Hi)/1e3||0}get waiting(){return this.Qi}Vi(t){let s;this.Yi+=t,s=setTimeout((()=>{this.Yi-=t,this.zi.delete(s),this.zi.size||this.Ki()}),this.Yi),this.zi.add(s)}Ki(){this.Ji&&this.Ji(),this.Qi=new Promise((t=>{this.Ji=t}))}Zi(){this.zi&&this.zi.forEach((t=>clearTimeout(t))),this.zi=new Set,this.Yi=0,this.Ki()}async Xi(){let t;this.te=new Promise((t=>{this.se=t}));try{switch(this.X){case"mpeg":const{MPEGDecoderWebWorker:s}=await Promise.all([r.e(385),r.e(88)]).then(r.bind(r,121));t=s;break;case"opus":const{OpusDecoderWebWorker:i}=await Promise.all([r.e(385),r.e(694)]).then(r.bind(r,978));t=i;break;case"flac":const{FLACDecoderWebWorker:e}=await Promise.all([r.e(385),r.e(993)]).then(r.bind(r,655));t=e;break;case"vorbis":const{OggVorbisDecoderWebWorker:h}=await Promise.all([r.e(385),r.e(398)]).then(r.bind(r,994));t=h}}catch(t){return void this.As[P](e.PLAYBACK_ERROR,`Missing \`webaudio-${this.X}\` dependency.`,`Unable to playback playback \`${this.X}\` audio.`)}if(t){const s=await this.hi;this.se(),this.ie=new t(s)}else this.As[P](e.PLAYBACK_ERROR,"Unsupported `webaudio` playback codec: "+this.X)}async gi(){super.gi(),this.Gi=0,this.ee=0,this.he=0,this.Mt=0,this.Hi=void 0,this.Si=!1,this.Zi(),this.re=new Promise((t=>{this.ne=t}))}async start(t){this.ie||await this.Xi();const s=super.start(t);this.ne(),await s}async end(){super.end(),this.ie&&(this.ie.terminate(),this.ie=null),this.ui&&this.ui.stream.getTracks().forEach((t=>this.ui.stream.removeTrack(t))),this.gi()}async onStream(t){if("vorbis"!==this.X)switch(t=t.flatMap((t=>t.codecFrames||t)),this.syncState){case D:this.bi.initSync(),this.syncState=k;case k:[this.syncFrames,this.syncState,this.syncDelay]=await this.bi.sync(t),t=this.syncFrames}switch(this.syncState){case O:break;case $:t.length&&(this.Gi=t[t.length-1].totalDuration,this.ae(t))}}async ae(t){if(await this.te,this.ie){let s;await this.ie.ready,"vorbis"===this.X?s=this.ie.decodeOggPages(t):(s=this.ie.decodeFrames(t.map((t=>t.data))),this.bi.addAll(t)),s.then((t=>this.oe(t)))}}async oe({channelData:t,samplesDecoded:s,sampleRate:h}){if(await this.re,this.As.state!==i.STOPPING&&this.As.state!==i.STOPPED&&s){this.As[P](e.STREAM,{channelData:t,samplesDecoded:s,sampleRate:h}),this.Mt||(this.Mt=h,this.ui=this.Wi.createMediaStreamDestination(),this.ui.channelCount=this.Wi.destination.maxChannelCount,this.ri.srcObject=this.ui.stream);const i=this.Wi.createBuffer(t.length,s,this.Mt);t.forEach(((t,s)=>i.getChannelData(s).set(t)));const r=this.Wi.createBufferSource();r.buffer=i,r.connect(this.ui);const n=100,a=this.ee*n+this.he,o=Math.round(this.Wi.currentTime*this.Mt*n);a<o&&(this.he+=o-a),r.start(a/this.Mt/n),this.Vi(s/this.Mt*1e3),this.Si||(this.ni<=this.metadataTimestamp?(this.As[P](e.PLAY_READY),this.Hi=performance.now(),this.pi(),this.As[P](e.PLAY),this.Si=!0):this.As[P](e.BUFFER,this.metadataTimestamp)),this.ee+=s}}}class ht{constructor(i){const e=s.get(i);this.As=i,this.ri=e[l],this.lt=e[p],this.ce=e[q],this.ue="",this.le(),this.Os=new tt(this.As),this.Os.icecastMetadataQueue=this.fi,this.Os.codecUpdateQueue=this.mi,this.Os.enablePlayButton(ht.supportedPlaybackMethods),this.de=[],this.I=void 0,this.ut="",this.X="",this.ye=Promise.resolve(),this.fe=t}static get supportedPlaybackMethods(){return[it,et,st].map((t=>t.isSupported?t.name:""))}static canPlayType(t){return{mediasource:it.canPlayType(t),html5:st.canPlayType(t),webaudio:et.canPlayType(t)}}get endpoint(){return this.ei}get player(){return this.Os}get playbackMethod(){return this.ue}get icyMetaInt(){return this.me&&this.me.icyMetaInt}async playStream(){return this.fetchStream().then((async t=>(this.As[P](e.STREAM_START),this.readIcecastResponse(t).finally((()=>{this.As[P](e.STREAM_END)}))))).catch((t=>{if(this.As.state!==i.SWITCHING)throw t}))}async switchStream(){this.As.state!==i.PLAYING&&(this.fe(),await this.ye);const t=s.get(this.As);t[x]=i.SWITCHING,t[R].abort(),t[R]=new AbortController}async fetchStream(){const t=s.get(this.As);this.ei=t[C].next().value;const i=t[I]?{"Icy-MetaData":1}:{};if(i.Range="bytes=0-",t[M]){const s=t[M];i.Authorization="Basic "+btoa(s.user+":"+s.password)}const e=await fetch(this.ei,{method:"GET",headers:i,signal:t[R].signal});if(!e.ok){const t=new Error(`${e.status} received from ${e.url}`);throw t.name="HTTP Response Error",t}return e}async readIcecastResponse(t){const i=t.headers.get("content-type"),h=s.get(this.As);let r;const n=new Promise((t=>{r=t})),a=new Promise((t=>{this.I=new K.Ay(i,{onCodec:t,onCodecHeader:r,onCodecUpdate:this.ce&&((...t)=>this.Os.onCodecUpdate(...t)),enableLogging:this.lt})}));this.me=new V(t,{onMetadata:async t=>{this.Os.onMetadata(t)},onStream:async({stream:t})=>{this.As[P](e.STREAM,t);const s=[...this.I.parseChunk(t)];if(this.Os.isAudioPlayer){const t=[...this.de,...s];this.de=[],await this.Os.onStream(t)}else this.de.push(...s)},onError:(...t)=>this.As[P](e.WARN,...t),metadataTypes:h[o],icyCharacterEncoding:h[f],icyDetectionTimeout:h[m],...h[y]?{icyMetaInt:h[y]}:{}});const c=this.me.startReading(),u=await a;this.Os.isAudioPlayer||([this.Os,this.ue]=this.pe(i,u,n)),this.Os.syncState===$?this.Os.start():await this.ge(i,u,n),await c}async ge(t,s,e){let h,r,n=!1,a=!1;const o=this.Os,c=this.Os.icecastMetadataQueue,u=this.Os.codecUpdateQueue;this.le(),o.icecastMetadataQueue=this.fi,o.codecUpdateQueue=this.mi;const l=()=>{a=!0,this.As.state===i.STOPPING&&this.As.state===i.STOPPED||(o.icecastMetadataQueue.purgeMetadataQueue(),o.codecUpdateQueue.purgeMetadataQueue(),this.Os.start(Math.max(0,o.syncDelay/1e3)).then((()=>o.end())).then(r))};this.fe=()=>{n=!0,this.fi.purgeMetadataQueue(),this.mi.purgeMetadataQueue(),this.Os.icecastMetadataQueue=c,this.Os.codecUpdateQueue=u,void 0===h||a||(clearTimeout(h),l())};const d=()=>this.Os.syncStateUpdate.then((a=>{if(n)r();else switch(a){case k:return d();case $:this.fi.purgeMetadataQueue(),this.mi.purgeMetadataQueue(),this.Os.icecastMetadataQueue=c,this.Os.codecUpdateQueue=u,this.As.state===i.STOPPING&&this.As.state===i.STOPPED||(this.As[x]=i.PLAYING),r();break;case O:case D:o.icecastMetadataQueue=c,o.codecUpdateQueue=u,[this.Os,this.ue]=this.pe(t,s,e),this.de.push(...o.syncFrames),h=setTimeout(l,Math.max(o.syncDelay,0))}}));let y;this.ye=new Promise((t=>{r=t,y=()=>{this.fe(),r()},this.As.addEventListener(i.STOPPING,y,{once:!0}),d()})).finally((()=>{this.As.removeEventListener(i.STOPPING,y)}))}le(){this.fi=new z({onMetadataUpdate:(...t)=>this.As[P](e.METADATA,...t),onMetadataEnqueue:(...t)=>this.As[P](e.METADATA_ENQUEUE,...t),paused:!0}),this.mi=new z({onMetadataUpdate:(...t)=>this.As[P](e.CODEC_UPDATE,...t),paused:!0})}pe(t,i,e){const{[s.get(this.As)[c]]:h,...r}={mediasource:it,webaudio:et,html5:st};let n,a;for(const s of Object.values({firstMethod:h,...r})){const h=s.canPlayType(`${t};codecs="${i}"`);if("probably"===h||"maybe"===h){a=s.name,n=new s(this.As,this.ei,t,i,e),n.icecastMetadataQueue=this.fi,n.codecUpdateQueue=this.mi;break}}if(!n)throw new Error(`Your browser does not support this audio codec ${t}${i&&`;codecs="${i}"`}`);return[n,a]}}let rt;try{new window.EventTarget,rt=window.EventTarget}catch{rt=L}const nt=Symbol(),at=Symbol(),ot=Symbol(),ct=Symbol(),ut=Symbol(),lt=Symbol(),dt=Symbol(),yt=Symbol(),ft=Symbol(),mt=Symbol(),pt=Symbol(),wt=Symbol();class gt extends rt{static*[A](t){for(;;){const i=s.get(t)[h];for(const e of i)if(yield e,s.get(t)[h]!==i)break}}static[v](t,s,i={}){const e={[h]:(t&&(Array.isArray(t)?t:[t]))??i[h],[d]:s.bufferLength??i[d]??1,[y]:s.icyMetaInt??i[y],[f]:s.icyCharacterEncoding??i[f],[m]:s.icyDetectionTimeout??i[m],[o]:(s.metadataTypes??i[o])||["icy"],[I]:((s.metadataTypes??i[o])||["icy"]).includes("icy"),[p]:s.enableLogging??i[p]??!1,[q]:Boolean(s.enableCodecUpdate??i[q]??s.onCodecUpdate),[a]:s.endpointOrder??i[a]??"ordered",[w]:s.retryDelayRate??i[w]??.1,[g]:s.retryDelayMin??i[g]??.5,[b]:s.retryDelayMax??i[b]??2,[S]:s.retryTimeout??i[S]??30,[c]:(s.playbackMethod??i[c])||"mediasource",[M]:s.authentication??i[M]};return e[h]!==i[h]&&"random"===e[a]&&(e[h]=e[h].sort((()=>.5-Math.random()))),e}constructor(h,r={}){super(),s.set(this,{[C]:gt[A](this),[l]:r.audioElement||new Audio,...gt[v](h,r),[ot]:{[e.PLAY]:r.onPlay||t,[e.PLAY_READY]:t,[e.LOAD]:r.onLoad||t,[e.STREAM_START]:r.onStreamStart||t,[e.BUFFER]:r.onBuffer||t,[e.STREAM]:r.onStream||t,[e.STREAM_END]:r.onStreamEnd||t,[e.METADATA]:r.onMetadata||t,[e.METADATA_ENQUEUE]:r.onMetadataEnqueue||t,[e.CODEC_UPDATE]:r.onCodecUpdate||t,[e.STOP]:r.onStop||t,[e.RETRY]:r.onRetry||t,[e.RETRY_TIMEOUT]:r.onRetryTimeout||t,[e.SWITCH]:r.onSwitch||t,[e.WARN]:(...t)=>{this[T](console.warn,r.onWarn,t)},[e.ERROR]:(...t)=>{this[T](console.error,r.onError,t)},[e.PLAYBACK_ERROR]:(...t)=>{this.state!==i.RETRYING?(this[P](e.ERROR,...t),this.stop()):s.get(this)[mt]()}},[mt]:()=>{clearTimeout(s.get(this)[wt]),this.removeEventListener(e.STREAM_START,s.get(this)[mt]),s.get(this)[l].removeEventListener("waiting",s.get(this)[yt]);try{s.get(this)[l].pause()}catch(t){s.get(this)[dt](t)}try{s.get(this)[at]=s.get(this)[nt].player.end()}catch{}},[ut]:()=>{this.play()},[ct]:()=>{this.stop()},[dt]:t=>{const s=t?.target?.error||t;this[P](e.PLAYBACK_ERROR,"The audio element encountered an error."+({1:" MEDIA_ERR_ABORTED The fetching of the associated resource was aborted by the user's request.",2:" MEDIA_ERR_NETWORK Some kind of network error occurred which prevented the media from being successfully fetched, despite having previously been available.",3:" MEDIA_ERR_DECODE Despite having previously been determined to be usable, an error occurred while trying to decode the media resource, resulting in an error.",4:" MEDIA_ERR_SRC_NOT_SUPPORTED The associated resource or media provider object (such as a MediaStream) has been found to be unsuitable.",5:" MEDIA_ERR_ENCRYPTED"}[s?.code]||""))},[lt]:()=>{const t=s.get(this)[l];(this.state===i.LOADING||!t.loop&&this.state!==i.STOPPING&&this.state!==i.STOPPED)&&t.play().then((()=>{this[x]=i.PLAYING})).catch((t=>{this[P](e.PLAYBACK_ERROR,t,"Playback failed.")}))},[ft]:t}),this[E](),this[x]=i.STOPPED,s.get(this)[nt]=new ht(this)}static canPlayType(t){return ht.canPlayType(t)}get audioElement(){return s.get(this)[l]}get[u](){return gt.constructor[u]}get endpoint(){return s.get(this)[nt].endpoint}get icyMetaInt(){return s.get(this)[nt].icyMetaInt}get metadataQueue(){return s.get(this)[nt].player.metadataQueue}get state(){return s.get(this)[x]}get playbackMethod(){return s.get(this)[nt].playbackMethod}set[x](t){this.dispatchEvent(new CustomEvent(t)),s.get(this)[x]=t}[E](){const t=s.get(this)[l];t.addEventListener("pause",s.get(this)[ct]),t.addEventListener("play",s.get(this)[ut]),t.addEventListener("error",s.get(this)[dt]),this.addEventListener(e.PLAY_READY,s.get(this)[lt])}async detachAudioElement(){const t=s.get(this)[l];t.removeEventListener("pause",s.get(this)[ct]),t.removeEventListener("play",s.get(this)[ut]),t.removeEventListener("error",s.get(this)[dt]),this.removeEventListener(e.PLAY_READY,s.get(this)[lt]),await this.stop()}async play(){if(this.state===i.STOPPED){const t=new Promise((t=>{this.addEventListener(e.PLAY,t,{once:!0})})),h=new Promise((t=>{this.addEventListener(e.STREAM_END,t,{once:!0})}));s.get(this)[R]=new AbortController,this[x]=i.LOADING,this[P](e.LOAD);const r=async()=>s.get(this)[nt].playStream().then((async()=>{if(this.state===i.SWITCHING)return this[P](e.SWITCH),r();this.state!==i.STOPPING&&this.state!==i.STOPPED&&(await t,await h,await s.get(this)[nt].player.waiting)})).catch((async t=>{if(t&&"AbortError"!==t.name){if(await this[_](t))return this[P](e.RETRY),r();s.get(this)[R].abort(),this.state!==i.STOPPING&&this.state!==i.STOPPED&&this[P](e.ERROR,t.message.match(/network|fetch|offline|codec/i)?t:t.stack,t)}}));new Promise(((t,i)=>{s.get(this)[ft]=i,r().then(t)})).catch((t=>{if(this.state!==i.STOPPING)throw t})).finally((()=>{s.get(this)[mt](),this[P](e.STOP),this[x]=i.STOPPED})),await t}}async stop(){this.state!==i.STOPPED&&this.state!==i.STOPPING&&(this[x]=i.STOPPING,s.get(this)[R].abort(),s.get(this)[ft](),await new Promise((t=>{this.addEventListener(e.STOP,t,{once:!0})})))}async switchEndpoint(t,e){if(this.state!==i.STOPPED&&this.state!==i.STOPPING){const i=s.get(this);return Object.assign(i,gt[v](t,e,i)),i[nt].switchStream()}}async[_](t){if(0===s.get(this)[S])return!1;if(s.get(this)[x]===i.RETRYING)return await new Promise((t=>{this.addEventListener(i.STOPPING,t,{once:!0});const e=Math.min(1e3*s.get(this)[g]*(s.get(this)[w]+1)**s.get(this)[pt]++,1e3*s.get(this)[b]);setTimeout((()=>{this.removeEventListener(i.STOPPING,t),t()}),e+.3*e*Math.random())})),s.get(this)[x]===i.RETRYING;if(s.get(this)[x]!==i.STOPPING&&s.get(this)[x]!==i.STOPPED&&(t.message.match(/network|fetch|offline|Error in body stream/i)||"HTTP Response Error"===t.name)){this[P](e.ERROR,t.name,t),this[x]=i.RETRYING,s.get(this)[I]&&this[P](e.WARN,"This stream was requested with ICY metadata.",'If there is a CORS preflight failure, try removing "icy" from the metadataTypes option.',"See https://github.com/eshaz/icecast-metadata-js#cors for more details.");const h=new Promise((t=>{s.get(this)[yt]=t,s.get(this)[l].addEventListener("waiting",s.get(this)[yt],{once:!0})}));return s.get(this)[wt]=setTimeout((()=>{h.then((()=>{s.get(this)[x]===i.RETRYING&&(this[P](e.RETRY_TIMEOUT),this.stop())}))}),1e3*s.get(this)[S]),s.get(this)[pt]=0,!0}return!1}[P](t,...i){this.dispatchEvent(new CustomEvent(t,{detail:i})),s.get(this)[ot][t](...i)}[T](t,i,e){s.get(this)[p]&&t("icecast-metadata-js",e.reduce(((t,s)=>t+"\n "+s),"")),i&&i(...e)}}const bt=window.AudioContext||window.webkitAudioContext;if(bt&&!gt.constructor[u]){gt.constructor[u]="audio context pending";const t=t=>{console.error("icecast-metadata-js","Failed to start the AudioContext. WebAudio playback will not be possible.",t)},s=["touchstart","touchend","mousedown","keydown"],i=()=>{s.forEach((t=>document.removeEventListener(t,i)));const e=new bt({latencyHint:"interactive"});e.destination.channelCount=e.destination.maxChannelCount,e.resume().then((()=>{e.createScriptProcessor(16384,2,2).connect(e.destination),e.onstatechange=()=>{"running"!==e.state&&e.resume().catch(t)}})).catch(t),gt.constructor[u]=e};s.forEach((t=>document.addEventListener(t,i)))}})(),n=r.O(n),IcecastMetadataPlayer=n.default})();
//# sourceMappingURL=icecast-metadata-player-1.17.3.main.min.js.map