rx-player 4.4.0-dev.2025092200 → 4.4.0-dev.2025092404

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Changelog
2
2
 
3
- ## Current dev build: v4.4.0-dev.2025092200
3
+ ## Current dev build: v4.4.0-dev.2025092404
4
4
 
5
5
  ### Features
6
6
 
package/VERSION CHANGED
@@ -1 +1 @@
1
- 4.4.0-dev.2025092200
1
+ 4.4.0-dev.2025092404
@@ -190,7 +190,7 @@ var Player = /** @class */ (function (_super) {
190
190
  // Workaround to support Firefox autoplay on FF 42.
191
191
  // See: https://bugzilla.mozilla.org/show_bug.cgi?id=1194624
192
192
  videoElement.preload = "auto";
193
- _this.version = /* PLAYER_VERSION */ "4.4.0-dev.2025092200";
193
+ _this.version = /* PLAYER_VERSION */ "4.4.0-dev.2025092404";
194
194
  _this.log = log_1.default;
195
195
  _this.state = "STOPPED";
196
196
  _this.videoElement = videoElement;
@@ -2903,5 +2903,5 @@ var Player = /** @class */ (function (_super) {
2903
2903
  Player._priv_currentlyUsedVideoElements = new WeakSet();
2904
2904
  return Player;
2905
2905
  }(event_emitter_1.default));
2906
- Player.version = /* PLAYER_VERSION */ "4.4.0-dev.2025092200";
2906
+ Player.version = /* PLAYER_VERSION */ "4.4.0-dev.2025092404";
2907
2907
  exports.default = Player;
@@ -172,7 +172,7 @@ class Player extends EventEmitter {
172
172
  // Workaround to support Firefox autoplay on FF 42.
173
173
  // See: https://bugzilla.mozilla.org/show_bug.cgi?id=1194624
174
174
  videoElement.preload = "auto";
175
- this.version = /* PLAYER_VERSION */ "4.4.0-dev.2025092200";
175
+ this.version = /* PLAYER_VERSION */ "4.4.0-dev.2025092404";
176
176
  this.log = log;
177
177
  this.state = "STOPPED";
178
178
  this.videoElement = videoElement;
@@ -2679,5 +2679,5 @@ class Player extends EventEmitter {
2679
2679
  * Use of a WeakSet ensure the object is garbage collected if it's not used anymore.
2680
2680
  */
2681
2681
  Player._priv_currentlyUsedVideoElements = new WeakSet();
2682
- Player.version = /* PLAYER_VERSION */ "4.4.0-dev.2025092200";
2682
+ Player.version = /* PLAYER_VERSION */ "4.4.0-dev.2025092404";
2683
2683
  export default Player;
package/dist/rx-player.js CHANGED
@@ -39840,7 +39840,7 @@ ${event}`
39840
39840
  } = parseConstructorOptions(options);
39841
39841
  videoElement.preload = "auto";
39842
39842
  this.version = /* PLAYER_VERSION */
39843
- "4.4.0-dev.2025092200";
39843
+ "4.4.0-dev.2025092404";
39844
39844
  this.log = log_default;
39845
39845
  this.state = "STOPPED";
39846
39846
  this.videoElement = videoElement;
@@ -42567,7 +42567,7 @@ ${event}`
42567
42567
  _Player._priv_currentlyUsedVideoElements = /* @__PURE__ */ new WeakSet();
42568
42568
  var Player = _Player;
42569
42569
  Player.version = /* PLAYER_VERSION */
42570
- "4.4.0-dev.2025092200";
42570
+ "4.4.0-dev.2025092404";
42571
42571
  var public_api_default = Player;
42572
42572
 
42573
42573
  // src/main_thread/api/index.ts
@@ -20,4 +20,4 @@ Char: `+n[t])}return t!==-1&&(t+=1),I}else if(n.charCodeAt(t+1)===yy){if(n.charC
20
20
  `+Xb(t.buffered,t.position.getPolled()),`
21
21
  ${e}`),this._observationRef.setValue(t)}};function Rp(n,e){if(n===null)return 0;let t=e?"LOW_LATENCY":"DEFAULT",{RESUME_GAP_AFTER_SEEKING:r,RESUME_GAP_AFTER_NOT_ENOUGH_DATA:i,RESUME_GAP_AFTER_BUFFERING:o}=O.getCurrent();switch(n.reason){case"seeking":return r[t];case"not-ready":return i[t];case"buffering":return o[t]}}function Yb(n,e,t,r,i){let{REBUFFERING_GAP:o}=O.getCurrent(),a=i?"LOW_LATENCY":"DEFAULT";return e===void 0?t&&Math.abs(r-n)<=o[a]:e!==null&&r-e.end<=o[a]}function kp(n){let{buffered:e,currentTime:t,duration:r,ended:i,paused:o,playbackRate:a,readyState:s,seeking:d}=n;return{buffered:e,position:t,duration:r,ended:i,paused:o,playbackRate:a,readyState:s,seeking:d}}function Qb({previousObservation:n,currentObservation:e,basePosition:t,observationEvent:r,withMediaSource:i,lowLatencyMode:o,bufferGap:a,fullyLoaded:s}){let{REBUFFERING_GAP:d}=O.getCurrent(),{position:u,paused:c,readyState:l,ended:f}=e,{rebuffering:p,event:h,position:I}=n,g=p===null&&!(s||f),b=null,T,v,_=o?d.LOW_LATENCY:d.DEFAULT;if(i){if(g)a===1/0?(T=!0,b=t):a===void 0?l<3&&(T=!0,b=void 0):a<=_&&(T=!0,b=t+a);else if(p!==null){let R=Rp(p,o);T!==!0&&p!==null&&l>1&&(s||f||a!==void 0&&isFinite(a)&&a>R)||a===void 0&&l>=3?v=!0:a===void 0?b=void 0:a===1/0?b=t:a<=R&&(b=t+a)}}else g&&(!c&&r==="timeupdate"&&h==="timeupdate"&&u===I.getPolled()||r==="seeking"&&(a===1/0||a===void 0&&l<3))?T=!0:p!==null&&(r!=="seeking"&&u!==I.getPolled()||r==="canplay"||a===void 0&&l>=3||a!==void 0&&a<1/0&&(a>Rp(p,o)||s||f))&&(v=!0);if(v===!0)return null;if(T===!0||p!==null){let R;return r==="seeking"||p!==null&&p.reason==="seeking"||e.seeking?R="seeking":l===1?R="not-ready":R="buffering",p!==null&&p.reason===R?{reason:p.reason,timestamp:p.timestamp,position:b}:{reason:R,timestamp:z(),position:b}}return null}function $b(n,e,t,r){let{MINIMUM_BUFFER_AMOUNT_BEFORE_FREEZING:i}=O.getCurrent();return n.freezing!==null?e.ended||e.paused||e.readyState===0||e.playbackRate===0||n.position.getPolled()!==e.position?null:n.freezing:t==="timeupdate"&&r!==void 0&&r>i&&!e.ended&&!e.paused&&e.readyState>=1&&e.playbackRate!==0&&e.position===n.position.getPolled()?{timestamp:z()}:null}function Xb(n,e){let t="",r="";for(let i=0;i<n.length;i++){let o=n.start(i),a=n.end(i),s=o.toFixed(2),d=a.toFixed(2),u=(a-o).toFixed(2),c=`${s}|==${u}==|${d}`;if(t+=c,r.length===0&&a>e){let l=t.length-Math.floor(c.length/2);r=" ".repeat(l)+`^${e}`}if(i<n.length-1){let l=n.start(i+1),p=` ~${(l-a).toFixed(2)}~ `;if(t+=p,r.length===0&&e<l){let h=t.length-Math.floor(p.length/2);r=" ".repeat(h)+`^${e}`}}}return r.length===0&&(r=" ".repeat(t.length)+`^${e}`),t+`
22
22
  `+r}function Zb(n){let e=kp(n);return Y(e,{rebuffering:null,event:"init",seeking:0,position:new or(e.position,null),freezing:null,bufferGap:0,currentRange:null,fullyLoaded:!1})}async function zl(n,e){let{time:t,container:r}=e;if(n===null||n.fetchThumbnailDataCallback===null||n.manifest===null)return Promise.reject(new gt("NO_CONTENT","Cannot get thumbnail: no content loaded"));let{thumbnailRequestsInfo:i,currentContentCanceller:o}=n,a=new U,s=a.linkToSignal(o.signal),d,u=i.pendingRequests.get(r);u==null||u.cancel(),i.pendingRequests.set(r,a);let c=()=>{s(),a.cancel(),i.pendingRequests.delete(r),setTimeout(()=>{d!==void 0&&URL.revokeObjectURL(d)},0)};try{let f=Hn(n.manifest,t);if(f===void 0)throw new gt("NO_THUMBNAIL","Wanted Period not found.");let p=f.thumbnailTracks,h=e.thumbnailTrackId!==void 0?Q(p,k=>k.id===e.thumbnailTrackId):p[0];if(h===void 0)throw e.thumbnailTrackId!==void 0?new gt("NO_THUMBNAIL","Given `thumbnailTrackId` not found"):new gt("NO_THUMBNAIL","Wanted Period has no thumbnail track.");let{lastResponse:I}=i,g;if(I!==null&&I.thumbnailTrackId===h.id&&I.periodId===f.id){let k=I.response.thumbnails;k.length>0&&t>=k[0].start&&t<k[k.length-1].end&&(g=I.response)}if(g===void 0&&(g=await n.fetchThumbnailDataCallback(f.id,h.id,t),i.lastResponse={response:g,periodId:f.id,thumbnailTrackId:h.id}),a.signal.cancellationError!==null)throw a.signal.cancellationError;let b=document.createElement("canvas"),T=b.getContext("2d");if(T===null)throw new gt("RENDERING","Cannot display thumbnail: cannot create canvas context");let v=Ie(g.thumbnails,k=>k.start<=t&&k.end>t);if(v<0)throw new Error("Cannot display thumbnail: time not found in fetched data");let _=new Image,R=new Blob([g.data],{type:g.mimeType});return d=URL.createObjectURL(R),_.src=d,b.height=g.thumbnails[v].height,b.width=g.thumbnails[v].width,new Promise((k,x)=>{_.onload=()=>{if(a.signal.cancellationError!==null){x(a.signal.cancellationError),c();return}try{T.drawImage(_,g.thumbnails[v].offsetX,g.thumbnails[v].offsetY,g.thumbnails[v].width,g.thumbnails[v].height,0,0,g.thumbnails[v].width,g.thumbnails[v].height),b.style.width="100%",b.style.height="100%",b.className="__rx-thumbnail__",l(),r.appendChild(b),k()}catch(P){x(new gt("RENDERING","Could not draw the image in a canvas:"+(P instanceof Error?P.toString():"Unknown Error")))}c()},_.onerror=()=>{if(a.signal.cancellationError!==null){x(a.signal.cancellationError),c();return}e.keepPreviousThumbnailOnError!==!0&&l(),x(new gt("RENDERING","Could not load the corresponding image in the DOM")),c()}})}catch(f){if(e.keepPreviousThumbnailOnError!==!0&&l(),f!==null&&f===a.signal.cancellationError)throw new gt("ABORTED","Thumbnail rendering has been aborted");let p=Me(f,{defaultCode:"NONE",defaultReason:"Unknown error"}),h;throw p.type==="NETWORK_ERROR"?h=new gt("LOADING",p.message):h=new gt("NOT_FOUND",p.message),c(),h}function l(){for(let f=r.children.length-1;f>=0;f--){let p=r.children[f];p.className==="__rx-thumbnail__"&&r.removeChild(p)}}}var gt=class n extends Error{constructor(e,t){super(nt(e,t)),Object.setPrototypeOf(this,n.prototype),this.name="ThumbnailRenderingError",this.code=e}};var bo=class extends se{constructor(e){super(),this._canceller=new U,this._adaptationRef=e,this._updateToken=!1,this._lastEmitted=void 0,this.refresh=te}hasSetTrack(){return this._adaptationRef.getValue()!==void 0}updateTrack(e){if(this._updateToken=!0,e===null){if(this._lastEmitted===null)return;this._updateToken=!1,this._canceller.cancel(),this._canceller=new U,this._lastEmitted=null,this._adaptationRef.setValue(null);return}let{adaptation:t,switchingMode:r,relativeResumingPosition:i}=e;this._canceller.cancel(),this._canceller=new U;let o=this._constructLockedRepresentationsReference(e);this._updateToken&&(this._lastEmitted={adaptation:t,switchingMode:r,lockedRepresentations:null},this._updateToken=!1,this._adaptationRef.setValue({adaptationId:t.id,switchingMode:r,representations:o,relativeResumingPosition:i}))}_constructLockedRepresentationsReference(e){let t=new j({representationIds:[],switchingMode:"lazy"}),r=this;return this.refresh=i,this._canceller.signal.register(o),e.lockedRepresentations.onUpdate(i,{clearSignal:this._canceller.signal,emitCurrentValue:!1}),i(),t;function i(){let a=e.lockedRepresentations.getValue(),s,d;if(a===null)d=e.adaptation.representations.filter(l=>Rt(l)===!0),s="lazy";else{let{representationIds:l}=a;if(s=a.switchingMode,d=e.adaptation.representations.filter(p=>$(l,p.id)).filter(p=>Rt(p)===!0),d.length===0){r.trigger("noPlayableLockedRepresentation",null);return}}if(d.length<=0){r.trigger("noPlayableRepresentation",null);return}let u=t.getValue(),c=d.map(l=>l.id).slice().sort();if(c.length!==u.representationIds.length){t.setValue({representationIds:c,switchingMode:s});return}for(let l=0;l<c.length;l++)if(u.representationIds[l]!==c[l]){t.setValue({representationIds:c,switchingMode:s});return}}function o(){r.refresh=te}}dispose(){this.removeEventListener(),this._canceller.cancel(),this._adaptationRef.finish()}};var So=class extends se{constructor(e){var t;super(),this._storedPeriodInfo=[],this._isDisposed=!1,this._cachedPeriodInfo=new WeakMap,this._isTrickModeTrackEnabled=e.preferTrickModeTracks,this._defaultAudioTrackSwitchingMode=(t=e.defaultAudioTrackSwitchingMode)!=null?t:O.getCurrent().DEFAULT_AUDIO_TRACK_SWITCHING_MODE,this.onTracksNotPlayableForType=e.onTracksNotPlayableForType}getAvailablePeriods(){return this._storedPeriodInfo.reduce((e,t)=>(t.isPeriodAdvertised&&e.push(jt(t.period)),e),[])}onManifestCodecSupportUpdate(){this._selectInitialTrackIfNeeded()}checkPeriodHasSupportedTrack(e,t){var d,u;let r=e.adaptations[t],i=[...(d=e.adaptations.audio)!=null?d:[],...(u=e.adaptations.video)!=null?u:[]];if(!(r!==void 0&&r.length>0))return;let a=r.every(c=>c.supportStatus.hasSupportedCodec===!1),s=i.every(c=>c.supportStatus.hasSupportedCodec===!1);if(a){let c=new re("MANIFEST_INCOMPATIBLE_CODECS_ERROR","No supported "+t+" adaptations",{tracks:void 0});if(s){if(this.trigger("error",c),this._isDisposed)return;this.dispose();return}else if(this.onTracksNotPlayableForType[t]==="continue")this.trigger("warning",c);else{if(this.trigger("error",c),this._isDisposed)return;this.dispose();return}}}onManifestUpdate(e){var o,a,s;let{periods:t}=e;if(y.CURRENT_ENV===y.DEV)for(let d=1;d<t.length;d++)ne(t[d-1].start<=t[d].start);let r=[];for(let d of t)if(["audio","video"].forEach(u=>{this.checkPeriodHasSupportedTrack(d,u)}),this._isDisposed)return;let i=0;for(let d=0;d<this._storedPeriodInfo.length;d++){let u=this._storedPeriodInfo[d].period,c=t[i];if(c===void 0)for(let l=this._storedPeriodInfo.length-1;l>=d;l--)this._storedPeriodInfo[l].inManifest=!1,Wl(this._storedPeriodInfo[l])&&this._removePeriodObject(l);else if(u===c)i++,this.resetSelectedTrackIfNotAvailableAnymore(this._storedPeriodInfo[d],c,"video"),this.resetSelectedTrackIfNotAvailableAnymore(this._storedPeriodInfo[d],c,"audio"),this.resetSelectedTrackIfNotAvailableAnymore(this._storedPeriodInfo[d],c,"text");else if(u.start<=c.start)this._storedPeriodInfo[d].inManifest=!1,Wl(this._storedPeriodInfo[d])&&(this._removePeriodObject(d),d--);else{let l=Hl(c,!0);this._storedPeriodInfo.splice(d,0,l),r.push(l),i++}}if(i<t.length){let d=t.slice(i).map(u=>Hl(u,!0));this._storedPeriodInfo.push(...d),r.push(...d)}for(let d of this._storedPeriodInfo)(o=d.audio.dispatcher)==null||o.refresh(),(a=d.video.dispatcher)==null||a.refresh(),(s=d.text.dispatcher)==null||s.refresh()}onDecipherabilityUpdates(){var e,t,r;for(let i of this._storedPeriodInfo)(e=i.audio.dispatcher)==null||e.refresh(),(t=i.video.dispatcher)==null||t.refresh(),(r=i.text.dispatcher)==null||r.refresh()}resetSelectedTrackIfNotAvailableAnymore(e,t,r){var d;let i=e[r].storedSettings;if(E(i))return;let o=Ot(t,r);if(o.some(u=>u.id===i.adaptation.id)||(m.warn("Track",`Chosen ${r} Adaptation not available anymore`),r==="video"?e.video.storedSettings=this.getDefaultStoredSettingsForAdaptation(o,"video"):r==="audio"?e.audio.storedSettings=this.getDefaultStoredSettingsForAdaptation(o,"audio"):r==="text"&&(e.text.storedSettings=this.getDefaultStoredSettingsForAdaptation(o,"text")),this.trigger("trackUpdate",{period:jt(t),trackType:r,reason:"missing"}),this._isDisposed))return;let s=xt(this._storedPeriodInfo,e.period.id);s!==void 0&&s.isPeriodAdvertised&&s[r].storedSettings===null&&((d=s[r].dispatcher)==null||d.updateTrack(null))}getDefaultStoredSettingsForAdaptation(e,t){let{DEFAULT_VIDEO_TRACK_SWITCHING_MODE:r}=O.getCurrent();if(t==="text"||e.length===0)return null;switch(t){case"text":return null;case"video":{let i=e[0],o=Ja(i,this._isTrickModeTrackEnabled),a=new j(null);return{adaptationBase:i,adaptation:o,switchingMode:r,lockedRepresentations:a}}case"audio":return{adaptation:e[0],switchingMode:this._defaultAudioTrackSwitchingMode,lockedRepresentations:new j(null)};default:ze(t)}}addTrackReference(e,t,r){m.debug("Track","Adding Track Reference",{bufferType:e,periodId:t.id});let i=xt(this._storedPeriodInfo,t.id);if(i===void 0){i=Hl(t,!1);let s=!1;for(let d=0;d<this._storedPeriodInfo.length;d++)this._storedPeriodInfo[d].period.start>t.start&&(this._storedPeriodInfo.splice(d,0,i),s=!0);s||this._storedPeriodInfo.push(i)}i[e].dispatcher!==null&&(m.error("Track","Subject already added for type and Period",{bufferType:e,periodId:t.id}),i[e].dispatcher.dispose());let o=new bo(r);if(i[e].dispatcher=o,o.addEventListener("noPlayableRepresentation",()=>{this.handleMissingOrUnplayableTrack(t,e,!1)}),o.addEventListener("noPlayableLockedRepresentation",()=>{i!==void 0&&(this.unlockVideoRepresentations(i),this.trigger("brokenRepresentationsLock",{period:{id:t.id,start:t.start,end:t.end},trackType:e}))}),this._selectInitialTrackIfNeeded(),this._shouldAdvertisePeriod(i)&&(i.isPeriodAdvertised=!0,this.trigger("newAvailablePeriods",[{id:t.id,start:t.start,end:t.end}]),this._isDisposed))return;let a=["audio","video","text"];for(let s of a){let d=i[s];if(i.isPeriodAdvertised&&d.dispatcher!==null&&!d.dispatcher.hasSetTrack()&&d.storedSettings!==void 0&&d.dispatcher.updateTrack(d.storedSettings),this._isDisposed)return}}throwIfTracksAreNotSetForPeriod(e){let t=xt(this._storedPeriodInfo,e.id);if(t!==void 0&&["audio","video"].every(i=>t[i].storedSettings===null)){let i=new re("NO_AUDIO_VIDEO_TRACKS","No audio and no video tracks are set.");this.trigger("error",i),this.dispose()}}handleMissingOrUnplayableTrack(e,t,r){var u,c,l,f;let{fallbackTrack:i,noSourceMedia:o}=Jb(e,t),a=(u=xt(this._storedPeriodInfo,e.id))==null?void 0:u[t];if(a===void 0){m.warn("Track","Could not find period",{periodId:e.id});return}let s=a.storedSettings,d=()=>a.storedSettings!==s;if(i!==null){let p;t==="audio"?p=this._defaultAudioTrackSwitchingMode:t==="text"?p="direct":p="reload";let h={adaptation:i,switchingMode:p,lockedRepresentations:new j(null)};if(a.storedSettings=h,r||this.trigger("trackUpdate",{period:jt(e),trackType:t,reason:"no-playable-representation"}),this._isDisposed)return;a.storedSettings===h&&((c=a.dispatcher)==null||c.updateTrack(h))}else if(i===null&&!o){if(this.trigger("noPlayableTrack",{trackType:t,period:{id:e.id,start:e.start,end:e.end}}),this._isDisposed)return;let p=this.onTracksNotPlayableForType[t];if(!d()){if(p==="continue")m.warn("Track",`No playable ${t}, continuing without ${t}`),a.storedSettings=null,r||this.trigger("trackUpdate",{period:jt(e),trackType:t,reason:"no-playable-representation"}),a.storedSettings!==null||this._isDisposed||(l=a.dispatcher)==null||l.updateTrack(null);else if(p==="error"){let h=new re("NO_PLAYABLE_REPRESENTATION",`No ${t} Representation can be played`,{tracks:void 0});this.trigger("error",h)}}}else i===null&&o&&(m.debug("Track",`The period does not have adaptation for ${t} there is no track to choose`),a.storedSettings=null,r||this.trigger("trackUpdate",{period:jt(e),trackType:t,reason:"no-playable-representation"}),a.storedSettings!==null||this._isDisposed||(f=a.dispatcher)==null||f.updateTrack(null));this._isDisposed||t!=="text"&&this.throwIfTracksAreNotSetForPeriod(e)}removeTrackReference(e,t){m.debug("Track","Removing Track Reference",{bufferType:e,periodId:t});let r;for(let a=0;a<this._storedPeriodInfo.length;a++)if(this._storedPeriodInfo[a].period.id===t){r=a;break}if(r===void 0){m.warn("Track","type not found for period",{bufferType:e,periodId:t});return}let i=this._storedPeriodInfo[r],o=i[e];if((o==null?void 0:o.dispatcher)===null){m.warn("Track","TrackDispatcher already removed for type and Period",{bufferType:e,periodId:t});return}o.dispatcher.dispose(),o.dispatcher=null,Wl(i)&&this._removePeriodObject(r)}getPeriodObjectFromPeriod(e){let t=xt(this._storedPeriodInfo,e.id);return t===void 0&&e!==void 0?this._cachedPeriodInfo.get(e):t}getPeriodObjectFromId(e){return xt(this._storedPeriodInfo,e)}disableVideoTrickModeTracks(){this._isTrickModeTrackEnabled&&(this._isTrickModeTrackEnabled=!1,this._resetVideoTrackChoices("trickmode-disabled"))}enableVideoTrickModeTracks(){this._isTrickModeTrackEnabled||(this._isTrickModeTrackEnabled=!0,this._resetVideoTrackChoices("trickmode-enabled"))}resetPeriodObjects(){var e,t,r;m.debug("Track","Resetting Period Objects");for(let i=this._storedPeriodInfo.length-1;i>=0;i--){let o=this._storedPeriodInfo[i];(e=o.audio.dispatcher)==null||e.dispose(),o.audio.dispatcher=null,(t=o.video.dispatcher)==null||t.dispose(),o.video.dispatcher=null,(r=o.text.dispatcher)==null||r.dispose(),o.text.dispatcher=null,o.inManifest||this._removePeriodObject(i)}}isTrickModeEnabled(){return this._isTrickModeTrackEnabled}setAudioTrack(e){let{periodRef:t,trackId:r,switchingMode:i,lockedRepresentations:o,relativeResumingPosition:a}=e;return this._setAudioOrTextTrack({bufferType:"audio",periodRef:t,trackId:r,switchingMode:i!=null?i:this._defaultAudioTrackSwitchingMode,lockedRepresentations:o,relativeResumingPosition:a})}setTextTrack(e,t){return this._setAudioOrTextTrack({bufferType:"text",periodRef:e,trackId:t,switchingMode:"direct",lockedRepresentations:null,relativeResumingPosition:void 0})}_setAudioOrTextTrack({bufferType:e,periodRef:t,trackId:r,switchingMode:i,lockedRepresentations:o,relativeResumingPosition:a}){var p,h;if(!t.isPeriodAdvertised)throw new Error("Wanted Period not yet advertised.");let s=t.period,d=Q((p=s.adaptations[e])!=null?p:[],({id:I,supportStatus:g})=>g.hasSupportedCodec!==!1&&g.isDecipherable!==!1&&I===r);if(d===void 0)throw new Error(`Wanted ${e} track not found.`);let u=t[e],c;if(o===null)c=new j(null);else{let I=this._getRepresentationsToLock(d,o),g=e==="audio"?this._defaultAudioTrackSwitchingMode:"direct";c=new j({representationIds:I,switchingMode:g})}let l={adaptation:d,switchingMode:i,lockedRepresentations:c,relativeResumingPosition:a};if(u.storedSettings=l,this.trigger("trackUpdate",{period:jt(s),trackType:e,reason:"manual"}),this._isDisposed)return;let f=xt(this._storedPeriodInfo,s.id);f!==void 0&&f[e].storedSettings===l&&((h=f[e].dispatcher)==null||h.updateTrack(l))}setVideoTrack(e){var I,g;let{periodRef:t,trackId:r,switchingMode:i,lockedRepresentations:o,relativeResumingPosition:a}=e;if(!t.isPeriodAdvertised)throw new Error("Wanted Period not yet advertised.");let s=t.period,d=Q((I=s.adaptations.video)!=null?I:[],({id:b,supportStatus:T})=>T.isDecipherable!==!1&&T.hasSupportedCodec!==!1&&b===r);if(d===void 0)throw new Error("Wanted video track not found.");let{DEFAULT_VIDEO_TRACK_SWITCHING_MODE:u}=O.getCurrent(),c=t.video,l=Ja(d,this._isTrickModeTrackEnabled),f;if(o===null)f=new j(null);else{let b=this._getRepresentationsToLock(d,o),T=u;f=new j({representationIds:b,switchingMode:T})}let p={adaptationBase:d,switchingMode:i!=null?i:u,adaptation:l,relativeResumingPosition:a,lockedRepresentations:f};if(c.storedSettings=p,this.trigger("trackUpdate",{period:jt(s),trackType:"video",reason:"manual"}),this._isDisposed)return;let h=xt(this._storedPeriodInfo,s.id);h!==void 0&&h.video.storedSettings===p&&((g=h.video.dispatcher)==null||g.updateTrack(p))}disableTrack(e,t){var o,a;if(!e.isPeriodAdvertised)throw new Error("Wanted Period not yet advertised.");let r=e[t];if(r.storedSettings===null||(t!=="text"&&((o=e[t].storedSettings)==null||o.lockedRepresentations.finish()),r.storedSettings=null,this.trigger("trackUpdate",{period:jt(e.period),trackType:t,reason:"manual"}),this._isDisposed))return;let i=xt(this._storedPeriodInfo,e.period.id);if(i!==void 0&&i[t].storedSettings===null&&((a=i[t].dispatcher)==null||a.updateTrack(null)),i!==void 0&&["audio","video"].every(d=>i[d].storedSettings===null)){let d=new re("NO_AUDIO_VIDEO_TRACKS","No audio and no video tracks are set.");this.trigger("error",d),this.dispose();return}}getChosenAudioTrack(e,t){return E(e.audio.storedSettings)?null:Lo(e.audio.storedSettings.adaptation,t)}getChosenTextTrack(e){return E(e.text.storedSettings)?null:No(e.text.storedSettings.adaptation)}getChosenVideoTrack(e,t){return E(e.video.storedSettings)?null:Uo(e.video.storedSettings.adaptation,t)}getAvailableAudioTracks(e,t){let r=e.audio.storedSettings,i=E(r)?null:r.adaptation.id;return Ot(e.period,"audio").map(a=>{let s=i===null?!1:i===a.id;return Y(Lo(a,t),{active:s})})}getAvailableTextTracks(e){let t=e.text.storedSettings,r=E(t)?null:t.adaptation.id;return Ot(e.period,"text").map(o=>{let a=r===null?!1:r===o.id;return Y(No(o),{active:a})})}getAvailableVideoTracks(e,t){let r=e.video.storedSettings,i=E(r)?void 0:r.adaptation.id;return Ot(e.period,"video").map(a=>{let s=i===null?!1:i===a.id,d=Uo(a,t),u=d.trickModeTracks!==void 0?d.trickModeTracks.map(l=>{let f=i===null?!1:i===l.id;return Y(l,{active:f})}):[],c=Y(d,{active:s});return u!==void 0&&(c.trickModeTracks=u),c})}getLockedAudioRepresentations(e){let{storedSettings:t}=e.audio;if(E(t))return null;let r=t.lockedRepresentations.getValue();return r===null?null:r.representationIds}getLockedVideoRepresentations(e){let{storedSettings:t}=e.video;if(E(t))return null;let r=t.lockedRepresentations.getValue();return r===null?null:r.representationIds}lockAudioRepresentations(e,t){var s;let{storedSettings:r}=e.audio;if(E(r))return;let{DEFAULT_AUDIO_REPRESENTATIONS_SWITCHING_MODE:i}=O.getCurrent(),o=this._getRepresentationsToLock(r.adaptation,t.representations),a=(s=t.switchingMode)!=null?s:i;r.lockedRepresentations.setValue({representationIds:o,switchingMode:a})}lockVideoRepresentations(e,t){var s;let{storedSettings:r}=e.video;if(E(r))return;let{DEFAULT_VIDEO_REPRESENTATIONS_SWITCHING_MODE:i}=O.getCurrent(),o=this._getRepresentationsToLock(r.adaptation,t.representations),a=(s=t.switchingMode)!=null?s:i;r.lockedRepresentations.setValue({representationIds:o,switchingMode:a})}unlockAudioRepresentations(e){let{storedSettings:t}=e.audio;E(t)||t.lockedRepresentations.getValue()===null||t.lockedRepresentations.setValue(null)}unlockVideoRepresentations(e){let{storedSettings:t}=e.video;E(t)||t.lockedRepresentations.getValue()===null||t.lockedRepresentations.setValue(null)}dispose(){for(this._isDisposed=!0;;){let e=this._storedPeriodInfo.pop();if(e===void 0)return;e.isRemoved=!0}}_resetVideoTrackChoices(e){var r;for(let i=0;i<this._storedPeriodInfo.length;i++){let o=this._storedPeriodInfo[i];if(!E(o.video.storedSettings)){let a=o.video.storedSettings.adaptationBase;if(a!==null){let s=Ja(a,this._isTrickModeTrackEnabled);o.video.storedSettings.adaptationBase=a,o.video.storedSettings.adaptation=s}}}let t=this._storedPeriodInfo.slice();for(let i=0;i<t.length;i++){let o=t[i].period,s=t[i].video.storedSettings;if(s!==void 0){if(this.trigger("trackUpdate",{period:jt(o),trackType:"video",reason:e}),this._isDisposed)return;let d=xt(this._storedPeriodInfo,o.id);d!==void 0&&d.isPeriodAdvertised&&d.video.storedSettings===s&&((r=d.video.dispatcher)==null||r.updateTrack(s))}}}_removePeriodObject(e){ne(e<this._storedPeriodInfo.length);let t=this._storedPeriodInfo[e];this._storedPeriodInfo[e].isRemoved=!0,this._storedPeriodInfo.splice(e,1),this._cachedPeriodInfo.set(t.period,t)}_getRepresentationsToLock(e,t){let r=t.reduce((i,o)=>{let a=Q(e.representations,s=>s.id===o);return a===void 0?m.warn("Track","Wanted locked Representation not found."):i.push(a.id),i},[]);if(r.length===0)throw new Error("Cannot lock Representations: None of the given Representation id are found");return r}_selectInitialTrackIfNeeded(){var i,o,a,s;let{DEFAULT_VIDEO_TRACK_SWITCHING_MODE:e}=O.getCurrent(),t=[],r=[];for(let d of this._storedPeriodInfo){let{period:u}=d;if(d.audio.storedSettings!==void 0&&d.video.storedSettings!==void 0&&d.text.storedSettings!==void 0)continue;let c=[...(i=u.adaptations.audio)!=null?i:[],...(o=u.adaptations.video)!=null?o:[]],l=c.every(g=>g.supportStatus.hasCodecWithUndefinedSupport);if(c.length>0&&l)continue;let f=Ot(u,"audio")[0];if(f===void 0){if(d.audio.storedSettings=null,this.handleMissingOrUnplayableTrack(u,"audio",!0),this._isDisposed)return}else d.audio.storedSettings={adaptation:f,switchingMode:this._defaultAudioTrackSwitchingMode,lockedRepresentations:new j(null)};let p=Ot(u,"video")[0];if(p===void 0){if(d.video.storedSettings=null,this.handleMissingOrUnplayableTrack(u,"video",!0),this._isDisposed)return}else{let g=Ja(p,this._isTrickModeTrackEnabled);d.video.storedSettings={adaptation:g,adaptationBase:p,switchingMode:e,lockedRepresentations:new j(null)}}let h=null,I=((a=u.adaptations.text)!=null?a:[]).filter(g=>g.isForcedSubtitles===!0);if(I.length>0){if(f!=null){let g=Q(I,b=>b.normalizedLanguage===f.normalizedLanguage);g!==void 0&&(h=g)}h===null&&(h=(s=Q(I,g=>g.normalizedLanguage===void 0))!=null?s:null)}d.text.storedSettings=h===null?null:{adaptation:h,switchingMode:"direct",lockedRepresentations:new j(null)},r.push(d),this._shouldAdvertisePeriod(d)&&(d.isPeriodAdvertised=!0,t.push({id:u.id,start:u.start,end:u.end}))}if(!(t.length>0&&(this.trigger("newAvailablePeriods",t),this._isDisposed)))for(let d of r){if(!d.isPeriodAdvertised)continue;let u=["audio","video","text"];for(let c of u){let l=d[c];if(l.dispatcher!==null&&l.storedSettings!==void 0&&!l.dispatcher.hasSetTrack()&&(l.dispatcher.updateTrack(l.storedSettings),this._isDisposed))return}}}_shouldAdvertisePeriod(e){return!e.isPeriodAdvertised&&e.text.dispatcher!==null&&e.video.dispatcher!==null&&e.audio.dispatcher!==null}};function xt(n,e){for(let t=0;t<n.length;t++){let r=n[t];if(r.period.id===e)return r}}function Wl(n){var e,t,r;return!n.inManifest&&((e=n.text)==null?void 0:e.dispatcher)===null&&((t=n.audio)==null?void 0:t.dispatcher)===null&&((r=n.video)==null?void 0:r.dispatcher)===null}function Ja(n,e){var t;return e&&((t=n.trickModeTracks)==null?void 0:t[0])!==void 0?n.trickModeTracks[0]:n}function Hl(n,e){return{period:n,inManifest:e,isPeriodAdvertised:!1,isRemoved:!1,audio:{storedSettings:void 0,dispatcher:null},video:{storedSettings:void 0,dispatcher:null},text:{storedSettings:void 0,dispatcher:null}}}function jt(n){return{start:n.start,end:n.end,id:n.id}}function Jb(n,e){if(!(n.adaptations[e]!==void 0&&n.adaptations[e].length>0))return{fallbackTrack:null,noSourceMedia:!0};let r=eS(n,e);return{fallbackTrack:r!=null?r:null,noSourceMedia:!1}}function eS(n,e){var r;return Q((r=n.adaptations[e])!=null?r:[],i=>i.supportStatus.hasSupportedCodec===!1||i.supportStatus.isDecipherable===!1?!1:i.representations.filter(a=>Rt(a)===!0).length>0)}var Pp=So;function Cp(n){let e,t,r,i,o,a,{DEFAULT_BASE_BANDWIDTH:s,DEFAULT_VIDEO_RESOLUTION_LIMIT:d,DEFAULT_MAX_BUFFER_AHEAD:u,DEFAULT_MAX_BUFFER_BEHIND:c,DEFAULT_MAX_VIDEO_BUFFER_SIZE:l,DEFAULT_THROTTLE_VIDEO_BITRATE_WHEN_HIDDEN:f,DEFAULT_WANTED_BUFFER_AHEAD:p}=O.getCurrent();if(E(n.maxBufferAhead))e=u;else if(e=Number(n.maxBufferAhead),isNaN(e))throw new Error("Invalid maxBufferAhead parameter. Should be a number.");if(E(n.maxBufferBehind))t=c;else if(t=Number(n.maxBufferBehind),isNaN(t))throw new Error("Invalid maxBufferBehind parameter. Should be a number.");if(E(n.wantedBufferAhead))r=p;else if(r=Number(n.wantedBufferAhead),isNaN(r))throw new Error("Invalid wantedBufferAhead parameter. Should be a number.");if(E(n.maxVideoBufferSize))i=l;else if(i=Number(n.maxVideoBufferSize),isNaN(i))throw new Error("Invalid maxVideoBufferSize parameter. Should be a number.");let h=E(n.videoResolutionLimit)?d:n.videoResolutionLimit,I=E(n.throttleVideoBitrateWhenHidden)?f:!!n.throttleVideoBitrateWhenHidden;if(E(n.videoElement))o=document.createElement("video");else if(n.videoElement.nodeName.toLowerCase()==="video"||n.videoElement.nodeName.toLowerCase()==="audio")o=n.videoElement;else throw new Error("Invalid videoElement parameter. Should be a HTMLMediaElement.");if(E(n.baseBandwidth))a=s;else if(a=Number(n.baseBandwidth),isNaN(a))throw new Error("Invalid baseBandwidth parameter. Should be a number.");return{maxBufferAhead:e,maxBufferBehind:t,videoResolutionLimit:h,videoElement:o,wantedBufferAhead:r,maxVideoBufferSize:i,throttleVideoBitrateWhenHidden:I,baseBandwidth:a}}function Ap(n){var e,t,r,i;if(n===null||typeof n!="object"&&n!==void 0)throw new Error("API: reload - Invalid options format.");if((n==null?void 0:n.reloadAt)===null||typeof(n==null?void 0:n.reloadAt)!="object"&&(n==null?void 0:n.reloadAt)!==void 0)throw new Error("API: reload - Invalid 'reloadAt' option format.");if(typeof((e=n==null?void 0:n.reloadAt)==null?void 0:e.position)!="number"&&((t=n==null?void 0:n.reloadAt)==null?void 0:t.position)!==void 0)throw new Error("API: reload - Invalid 'reloadAt.position' option format.");if(typeof((r=n==null?void 0:n.reloadAt)==null?void 0:r.relative)!="number"&&((i=n==null?void 0:n.reloadAt)==null?void 0:i.relative)!==void 0)throw new Error("API: reload - Invalid 'reloadAt.relative' option format.");if(!Array.isArray(n==null?void 0:n.keySystems)&&(n==null?void 0:n.keySystems)!==void 0)throw new Error("API: reload - Invalid 'keySystems' option format.");if((n==null?void 0:n.autoPlay)!==void 0&&typeof n.autoPlay!="boolean")throw new Error("API: reload - Invalid 'autoPlay' option format.")}function Mp(n){var P,M,L,F;let e,t,r,i,o,a,s,{DEFAULT_AUTO_PLAY:d,DEFAULT_CODEC_SWITCHING_BEHAVIOR:u,DEFAULT_ENABLE_FAST_SWITCHING:c,DEFAULT_TEXT_TRACK_MODE:l,DEFAULT_AUDIO_TRACKS_NOT_PLAYABLE_BEHAVIOR:f,DEFAULT_VIDEO_TRACKS_NOT_PLAYABLE_BEHAVIOR:p}=O.getCurrent();if(E(n))throw new Error("No option set on loadVideo");if(!E(n.url))e=String(n.url);else if(E(n.initialManifest)&&E(n.manifestLoader))throw new Error("Unable to load a content: no url set on loadVideo.\nPlease provide at least either an `url` argument, a `initialManifest` option or a `manifestLoader` option so the RxPlayer can load the content.");if(E(n.transport))throw new Error("No transport set on loadVideo");t=String(n.transport);let h=E(n.autoPlay)?d:!!n.autoPlay;if(E(n.keySystems))r=[];else{r=Array.isArray(n.keySystems)?n.keySystems:[n.keySystems];for(let D of r)if(typeof D.type!="string"||typeof D.getLicense!="function")throw new Error("Invalid key system given: Missing type string or getLicense callback")}let I=n.lowLatencyMode===void 0?!1:!!n.lowLatencyMode,g=n.initialManifest,b=(P=n.minimumManifestUpdateInterval)!=null?P:0,T=(M=n.defaultAudioTrackSwitchingMode)!=null?M:void 0;T!==void 0&&!$(["seamless","direct","reload"],T)&&(m.warn("API","The `defaultAudioTrackSwitchingMode` loadVideo option must match one of the following strategy name:\n- `seamless`\n- `direct`\n- `reload`"),T=void 0);let v=E(n.onCodecSwitch)?u:n.onCodecSwitch;$(["continue","reload"],v)||(m.warn("API","The `onCodecSwitch` loadVideo option must match one of the following string:\n- `continue`\n- `reload`\nIf badly set, "+u+" will be used as default"),v=u);let _=E(n.onAudioTracksNotPlayable)?f:n.onAudioTracksNotPlayable;$(["continue","error"],_)||(m.warn("API","The `onAudioTracksNotPlayable` loadVideo option must match one of the following string:\n- `continue`\n- `error`\nIf badly set, "+f+" will be used as default"),_=f);let R=E(n.onVideoTracksNotPlayable)?p:n.onVideoTracksNotPlayable;if($(["continue","error"],R)||(m.warn("API","The `onVideoTracksNotPlayable` loadVideo option must match one of the following string:\n- `continue`\n- `error`\nIf badly set, "+p+" will be used as default"),R=p),E(n.textTrackMode))i=l;else{if(n.textTrackMode!=="native"&&n.textTrackMode!=="html")throw new Error("Invalid textTrackMode.");i=n.textTrackMode}if(i==="html"){if(E(n.textTrackElement))throw new Error('You have to provide a textTrackElement in "html" textTrackMode.');if(n.textTrackElement instanceof HTMLElement)a=n.textTrackElement;else throw new Error("textTrackElement should be an HTMLElement.")}else E(n.textTrackElement)||m.warn("API",'You have set a textTrackElement without being in an "html" textTrackMode. It will be ignored.');if(E(n.mode))o="auto";else{if(!$(["auto","multithread","main"],n.mode))throw new Error("Invalid `mode` option.");o=n.mode}let k=E(n.enableFastSwitching)?c:n.enableFastSwitching;if(!E(n.startAt))if("wallClockTime"in n.startAt&&n.startAt.wallClockTime instanceof Date){let D=n.startAt.wallClockTime.getTime()/1e3;s=Y({},n.startAt,{wallClockTime:D})}else s=n.startAt;let x=(L=n.requestConfig)!=null?L:{};return{__priv_patchLastSegmentInSidx:n.__priv_patchLastSegmentInSidx,__priv_manifestUpdateUrl:n.__priv_manifestUpdateUrl,checkMediaSegmentIntegrity:n.checkMediaSegmentIntegrity,checkManifestIntegrity:n.checkManifestIntegrity,autoPlay:h,defaultAudioTrackSwitchingMode:T,enableFastSwitching:k,initialManifest:g,keySystems:r,lowLatencyMode:I,manifestLoader:n.manifestLoader,minimumManifestUpdateInterval:b,requestConfig:x,onCodecSwitch:v,onAudioTracksNotPlayable:_,onVideoTracksNotPlayable:R,referenceDateTime:n.referenceDateTime,representationFilter:n.representationFilter,segmentLoader:n.segmentLoader,serverSyncInfos:n.serverSyncInfos,startAt:s,textTrackElement:a,textTrackMode:i,transport:t,mode:o,url:e,cmcd:n.cmcd,experimentalOptions:{enableRepresentationAvoidance:((F=n.experimentalOptions)==null?void 0:F.enableRepresentationAvoidance)===!0}}}function ql(n){return!(n&&(V.browser===V.BROWSERS.SafariMobile||V.browser===V.BROWSERS.SafariDesktop))}function xp(n,e,t,r){if(r.isCancelled())return;let i=n.getReference().getValue().seeking===2;i&&(e(),r.isCancelled())||n.listen(o=>{o.event==="seeking"?(i=!0,e()):i&&o.event==="seeked"&&(i=!1,t())},{includeLastObservation:!0,clearSignal:r})}function wp(n,e,t,r){r.isCancelled()||n===null||(n.addEventListener("play",e),n.addEventListener("pause",t),r.register(()=>{n.removeEventListener("play",e),n.removeEventListener("pause",t)}))}function Op(n,e,t,r,i){let o=new j("LOADING",i);n.addEventListener("loaded",()=>{if(o.getValue()==="LOADING"){if(o.setValue("LOADED"),!i.isCancelled()){let d=Gl(e,null,r,o.getValue());d!=="PAUSED"&&o.setValue(d)}}else o.getValue()==="RELOADING"?o.setValue(Gl(e,null,r,o.getValue())):s(null)},i),n.addEventListener("reloadingMediaSource",()=>{yr(o.getValue())&&o.setValueIfChanged("RELOADING")},i);let a=null;return n.addEventListener("stalled",d=>{d!==a&&(s(d),a=d)},i),n.addEventListener("unstalled",()=>{a!==null&&(s(null),a=null)},i),t.listen(d=>{$(["seeking","ended","play","pause"],d.event)&&s(a)},{clearSignal:i}),o;function s(d){if(!yr(o.getValue()))return;let u=Gl(e,d,r,o.getValue());o.getValue()==="LOADED"&&u==="PAUSED"||o.setValueIfChanged(u)}}function Gl(n,e,t,r){let{FORCED_ENDED_THRESHOLD:i}=O.getCurrent();if(n.ended)return"ENDED";if(e!==null){let o=Math.abs(n.duration-n.currentTime);return!E(i)&&o<i?"ENDED":e==="seeking"?"SEEKING":e==="freezing"?"FREEZING":r==="LOADED"&&!ql(t)?"LOADED":"BUFFERING"}return n.paused?"PAUSED":"PLAYING"}function yr(n){return n!=="LOADING"&&n!=="RELOADING"&&n!=="STOPPED"}var jl=Z,To=typeof jl.__RX_PLAYER_DEBUG_MODE__=="boolean"&&jl.__RX_PLAYER_DEBUG_MODE__;try{Object.defineProperty(jl,"__RX_PLAYER_DEBUG_MODE__",{get(){return To},set(n){To=n,n&&(Ir.LogLevel="DEBUG",Ir.LogFormat="full")}})}catch(n){}To?m.setLevel("DEBUG","full"):y.CURRENT_ENV===y.DEV&&m.setLevel(S.CURRENT_LEVEL,"standard");var tS=rt(),nS=["manifestLoader","segmentLoader"],Yt=class Yt extends se{static get ErrorTypes(){return tt}static get ErrorCodes(){return gs}static get LogLevel(){return m.getLevel()}static set LogLevel(e){m.setLevel(e,m.getFormat())}static get LogFormat(){return m.getFormat()}static set LogFormat(e){m.setLevel(m.getLevel(),e)}static addFeatures(e){ya(e)}static _priv_registerVideoElement(e){Yt._priv_currentlyUsedVideoElements.has(e)&&console.warn(`The video element is already attached to another RxPlayer instance.
23
- Make sure to dispose the previous instance with player.dispose() before creating a new player instance attaching that video element.`),Yt._priv_currentlyUsedVideoElements.add(e)}static _priv_deregisterVideoElement(e){Yt._priv_currentlyUsedVideoElements.has(e)&&Yt._priv_currentlyUsedVideoElements.delete(e)}constructor(e={}){super();let{baseBandwidth:t,videoResolutionLimit:r,maxBufferAhead:i,maxBufferBehind:o,throttleVideoBitrateWhenHidden:a,videoElement:s,wantedBufferAhead:d,maxVideoBufferSize:u}=Cp(e);s.preload="auto",this.version="4.4.0-dev.2025092200",this.log=m,this.state="STOPPED",this.videoElement=s,Yt._priv_registerVideoElement(this.videoElement);let c=new U;this._destroyCanceller=c,this._priv_pictureInPictureRef=Lc(s,c.signal),this._priv_speed=new j(s.playbackRate,this._destroyCanceller.signal),this._priv_preferTrickModeTracks=!1,this._priv_contentLock=new j(!1,this._destroyCanceller.signal),this._priv_bufferOptions={wantedBufferAhead:new j(d,this._destroyCanceller.signal),maxBufferAhead:new j(i,this._destroyCanceller.signal),maxBufferBehind:new j(o,this._destroyCanceller.signal),maxVideoBufferSize:new j(u,this._destroyCanceller.signal)},this._priv_bitrateInfos={lastBitrates:{audio:t,video:t}},this._priv_throttleVideoBitrateWhenHidden=a,this._priv_videoResolutionLimit=r,this._priv_currentError=null,this._priv_contentInfos=null,this._priv_contentEventsMemory={},this._priv_reloadingMetadata={},this._priv_lastAutoPlay=!1,this._priv_worker=null;let l=()=>{this.trigger("volumeChange",{volume:s.volume,muted:s.muted})};s.addEventListener("volumechange",l),c.signal.register(()=>{s.removeEventListener("volumechange",l)})}attachWorker(e){return new Promise((t,r)=>{var a;if(!Vl())return m.warn("API","Cannot rely on a WebWorker: Worker API unavailable"),r(new mn("INCOMPATIBLE_ERROR","Worker unavailable"));if(this._priv_worker!==null){if(this.state!=="STOPPED")return m.warn("API","Cannot attach a new worker while a content is playing, please stop the player first."),r(new mn("SETUP_ERROR","Cannot attach a new worker while a content is playing"));this._priv_worker.terminate()}if(typeof e.workerUrl=="string")this._priv_worker=new Worker(e.workerUrl);else{let s=URL.createObjectURL(e.workerUrl);this._priv_worker=new Worker(s),URL.revokeObjectURL(s)}this._priv_worker.onerror=s=>{this._priv_worker!==null&&(this._priv_worker.terminate(),this._priv_worker=null),m.error("API","Unexpected worker error",s.error instanceof Error?s.error:void 0),r(new mn("UNKNOWN_ERROR",'Unexpected Worker "error" event'))};let i=s=>{let d=s.data;d.type==="init-error"?(m.warn("API","Processing InitError worker message: detaching worker"),this._priv_worker!==null&&(this._priv_worker.removeEventListener("message",i),this._priv_worker.terminate(),this._priv_worker=null),r(new mn("SETUP_ERROR","Worker parser initialization failed: "+d.value.errorMessage))):d.type==="init-success"&&(m.info("API","InitSuccess received from worker."),this._priv_worker!==null&&this._priv_worker.removeEventListener("message",i),t())};this._priv_worker.addEventListener("message",i),m.debug("M-->C","Sending message",{name:"init"}),this._priv_worker.postMessage({type:"init",value:{dashWasmUrl:e.dashWasmUrl,logLevel:m.getLevel(),logFormat:m.getFormat(),sendBackLogs:To,date:Date.now(),timestamp:z(),hasVideo:((a=this.videoElement)==null?void 0:a.nodeName.toLowerCase())==="video"}}),m.addEventListener("onLogLevelChange",s=>{this._priv_worker!==null&&(m.debug("M-->C","Sending message",{name:"log-level-update"}),this._priv_worker.postMessage({type:"log-level-update",value:{logLevel:s.level,logFormat:s.format,sendBackLogs:To}}))},this._destroyCanceller.signal);let o=s=>{this._priv_worker!==null&&(m.debug("M-->C","Sending message:",{name:"config-update"}),this._priv_worker.postMessage({type:"config-update",value:s}))};O.updated&&o(O.getCurrent()),O.addEventListener("update",o,this._destroyCanceller.signal)})}getCurrentModeInformation(){return this._priv_contentInfos===null?null:{isDirectFile:this._priv_contentInfos.isDirectFile,useWorker:this._priv_contentInfos.useWorker}}addEventListener(e,t){return super.addEventListener(e,t)}stop(){this._priv_contentInfos!==null&&this._priv_contentInfos.currentContentCanceller.cancel(),this._priv_cleanUpCurrentContentState(),this.state!=="STOPPED"&&this._priv_setPlayerState("STOPPED")}dispose(){this.stop(),this.videoElement!==null&&(Yt._priv_deregisterVideoElement(this.videoElement),qn(this.videoElement).catch(e=>{let t=e instanceof Error?e.message:"Unknown error";m.error("API","Could not dispose decryption resources: "+t)})),this._destroyCanceller.cancel(),this._priv_reloadingMetadata={},this.videoElement=null,this._priv_worker!==null&&(this._priv_worker.terminate(),this._priv_worker=null)}loadVideo(e){let t=Mp(e);m.info("API","Calling loadvideo",{url:t.url,transport:t.transport}),this._priv_reloadingMetadata={options:t},this._priv_initializeContentPlayback(t),this._priv_lastAutoPlay=t.autoPlay}reload(e){var c,l,f;let{options:t,manifest:r,reloadPosition:i,reloadInPause:o}=this._priv_reloadingMetadata;if(t===void 0)throw new Error("API: Can't reload without having previously loaded a content.");Ap(e);let a;if(((c=e==null?void 0:e.reloadAt)==null?void 0:c.position)!==void 0)a={position:e.reloadAt.position};else if(((l=e==null?void 0:e.reloadAt)==null?void 0:l.relative)!==void 0){if(i===void 0)throw new Error("Can't reload to a relative position when previous content was not loaded.");a={position:e.reloadAt.relative+i}}else i!==void 0&&(a={position:i});let s;(e==null?void 0:e.autoPlay)!==void 0?s=e.autoPlay:o!==void 0&&(s=!o);let d;(e==null?void 0:e.keySystems)!==void 0?d=e.keySystems:((f=this._priv_reloadingMetadata.options)==null?void 0:f.keySystems)!==void 0&&(d=this._priv_reloadingMetadata.options.keySystems);let u=ue(ae({},t),{initialManifest:r});a!==void 0&&(u.startAt=a),s!==void 0&&(u.autoPlay=s),d!==void 0&&(u.keySystems=d),this._priv_initializeContentPlayback(u)}createDebugElement(e){if(pe.createDebugElement===null)throw new Error("Feature `DEBUG_ELEMENT` not added to the RxPlayer");let t=new U;return pe.createDebugElement(e,this,t.signal),{dispose(){t.cancel()}}}getAvailableThumbnailTracks({time:e,periodId:t}={}){if(this._priv_contentInfos===null||this._priv_contentInfos.manifest===null)return[];let{manifest:r}=this._priv_contentInfos,i;if(e!==void 0){if(i=Hn(this._priv_contentInfos.manifest,e),i===void 0||i.thumbnailTracks.length===0)return[]}else if(t!==void 0){if(i=Q(r.periods,o=>o.id===t),i===void 0)return m.error("API","getAvailableThumbnailTracks: periodId not found",{periodId:t}),[]}else{let{currentPeriod:o}=this._priv_contentInfos;if(o===null)return[];i=o}return i.thumbnailTracks.map(o=>({id:o.id,width:Math.floor(o.width/o.horizontalTiles),height:Math.floor(o.height/o.verticalTiles),mimeType:o.mimeType}))}async renderThumbnail(e){if(E(e.time))throw new Error("You have to provide a `time` property to `renderThumbnail`, indicating the wanted thumbnail time in seconds.");if(E(e.container))throw new Error("You have to provide a `container` property to `renderThumbnail`, specifying the HTML Element in which the thumbnail should be inserted.");return zl(this._priv_contentInfos,e)}_priv_initializeContentPlayback(e){var oe,fe,Re,ge,he,_t;let{autoPlay:t,cmcd:r,defaultAudioTrackSwitchingMode:i,enableFastSwitching:o,initialManifest:a,keySystems:s,lowLatencyMode:d,minimumManifestUpdateInterval:u,requestConfig:c,onCodecSwitch:l,startAt:f,transport:p,checkMediaSegmentIntegrity:h,checkManifestIntegrity:I,manifestLoader:g,referenceDateTime:b,segmentLoader:T,serverSyncInfos:v,mode:_,experimentalOptions:R,__priv_manifestUpdateUrl:k,__priv_patchLastSegmentInSidx:x,url:P,onAudioTracksNotPlayable:M,onVideoTracksNotPlayable:L}=e;if(this.videoElement===null)throw new Error("the attached video element is disposed");let F=p==="directfile",D=new U,B=this.videoElement,A,C=!1,N=null;if(F){if(pe.directfile===null)throw this.stop(),this._priv_currentError=null,new Error("DirectFile feature not activated in your build.");if(E(P))throw new Error("No URL for a DirectFile content");if(m.info("API","Initializing DirectFile mode in the main thread"),N=this._priv_initializeMediaElementTracksStore(D.signal),D.isUsed())return;A=new pe.directfile.initDirectFile({autoPlay:t,keySystems:s,speed:this._priv_speed,startAt:f,url:P})}else{let ee={lowLatencyMode:d,maxRetry:(oe=c.manifest)==null?void 0:oe.maxRetry,requestTimeout:(fe=c.manifest)==null?void 0:fe.timeout,connectionTimeout:(Re=c.manifest)==null?void 0:Re.connectionTimeout,minimumManifestUpdateInterval:u,initialManifest:a},ye=Kl(),ot={throttleBitrate:{},limitResolution:{}};this._priv_throttleVideoBitrateWhenHidden&&(ye?ot.throttleBitrate={video:gn(Nc(this._priv_pictureInPictureRef,D.signal),Qt=>Qt?1/0:0,D.signal)}:m.warn("API","Can't apply throttleVideoBitrateWhenHidden because browser can't be trusted for visibility.")),this._priv_videoResolutionLimit==="videoElement"?ye?ot.limitResolution={video:Bc(B,this._priv_pictureInPictureRef,D.signal)}:m.warn("API","Can't apply videoResolutionLimit because browser can't be trusted for video size."):this._priv_videoResolutionLimit==="screen"&&(ot.limitResolution={video:Uc(D.signal)});let pn={initialBitrates:this._priv_bitrateInfos.lastBitrates,lowLatencyMode:d,throttlers:ot},ht=e.textTrackMode==="native"?{textTrackMode:"native"}:{textTrackMode:"html",textTrackElement:e.textTrackElement},yt=Y({enableFastSwitching:o,onCodecSwitch:l},this._priv_bufferOptions),Yl={lowLatencyMode:d,maxRetry:(ge=c.segment)==null?void 0:ge.maxRetry,requestTimeout:(he=c.segment)==null?void 0:he.timeout,connectionTimeout:(_t=c.segment)==null?void 0:_t.connectionTimeout},Lp=pe.multithread!==null&&this._priv_worker!==null&&this.videoElement.FORCED_MEDIA_SOURCE===void 0&&p==="dash"&&nS.every(Qt=>E(e[Qt]))&&typeof e.representationFilter!="function";if(_==="main"||_==="auto"&&!Lp){if(pe.mainThreadMediaSourceInit===null)throw new Error("Cannot load video, neither in a WebWorker nor with the `MEDIA_SOURCE_MAIN` feature");let Qt=pe.transports[p];if(typeof Qt!="function")throw this.stop(),this._priv_currentError=null,new Error(`transport "${p}" not supported`);let Np=typeof e.representationFilter=="string"?Mc(e.representationFilter):e.representationFilter;m.info("API","Initializing MediaSource mode in the main thread");let Up=Qt({lowLatencyMode:d,checkMediaSegmentIntegrity:h,checkManifestIntegrity:I,manifestLoader:g,referenceDateTime:b,representationFilter:Np,segmentLoader:T,serverSyncInfos:v,__priv_manifestUpdateUrl:k,__priv_patchLastSegmentInSidx:x});A=new pe.mainThreadMediaSourceInit({adaptiveOptions:pn,autoPlay:t,bufferOptions:yt,cmcd:r,enableRepresentationAvoidance:R.enableRepresentationAvoidance,keySystems:s,lowLatencyMode:d,transport:Up,manifestRequestSettings:ee,segmentRequestOptions:Yl,speed:this._priv_speed,startAt:f,textTrackOptions:ht,url:P})}else{if(pe.multithread===null)throw new Error("Cannot load video in multithread mode: `MULTI_THREAD` feature not imported.");if(this._priv_worker===null)throw new Error("Cannot load video in multithread mode: `attachWorker` method not called.");ne(typeof e.representationFilter!="function"),C=!0,m.info("API","Initializing MediaSource mode in a WebWorker");let Qt={lowLatencyMode:d,checkMediaSegmentIntegrity:h,checkManifestIntegrity:I,referenceDateTime:b,serverSyncInfos:v,manifestLoader:void 0,segmentLoader:void 0,representationFilter:e.representationFilter,__priv_manifestUpdateUrl:k,__priv_patchLastSegmentInSidx:x};A=new pe.multithread.init({adaptiveOptions:pn,autoPlay:t,bufferOptions:yt,cmcd:r,enableRepresentationAvoidance:R.enableRepresentationAvoidance,keySystems:s,lowLatencyMode:d,transportOptions:Qt,manifestRequestSettings:ee,segmentRequestOptions:Yl,speed:this._priv_speed,startAt:f,textTrackOptions:ht,worker:this._priv_worker,url:P,useMseInWorker:vm})}}let K=new Io(B,{withMediaSource:!F,lowLatencyMode:d});K.blockSeeking(),D.signal.register(()=>{K.stop()});let q={contentId:tS(),originalUrl:P,playbackObserver:K,currentContentCanceller:D,defaultAudioTrackSwitchingMode:i,initializer:A,isDirectFile:F,manifest:null,currentPeriod:null,activeAdaptations:null,activeRepresentations:null,tracksStore:null,mediaElementTracksStore:N,useWorker:C,segmentSinkMetricsCallback:null,fetchThumbnailDataCallback:null,thumbnailRequestsInfo:{pendingRequests:new WeakMap,lastResponse:null},onAudioTracksNotPlayable:M,onVideoTracksNotPlayable:L};A.addEventListener("error",ee=>{this._priv_onFatalError(ee,q)}),A.addEventListener("warning",ee=>{let ye=Me(ee,{defaultCode:"NONE",defaultReason:"An unknown error happened."});m.warn("API","Sending warning:",ye),this.trigger("warning",ye)}),A.addEventListener("reloadingMediaSource",ee=>{q.tracksStore!==null&&q.tracksStore.resetPeriodObjects(),this._priv_contentInfos!==null&&(this._priv_contentInfos.segmentSinkMetricsCallback=null),this._priv_lastAutoPlay=ee.autoPlay}),A.addEventListener("inbandEvents",ee=>this.trigger("inbandEvents",ee)),A.addEventListener("streamEvent",ee=>this.trigger("streamEvent",ee)),A.addEventListener("streamEventSkip",ee=>this.trigger("streamEventSkip",ee)),A.addEventListener("activePeriodChanged",ee=>this._priv_onActivePeriodChanged(q,ee)),A.addEventListener("periodStreamReady",ee=>this._priv_onPeriodStreamReady(q,ee)),A.addEventListener("periodStreamCleared",ee=>this._priv_onPeriodStreamCleared(q,ee)),A.addEventListener("representationChange",ee=>this._priv_onRepresentationChange(q,ee)),A.addEventListener("adaptationChange",ee=>this._priv_onAdaptationChange(q,ee)),A.addEventListener("bitrateEstimateChange",ee=>this._priv_onBitrateEstimateChange(ee)),A.addEventListener("manifestReady",ee=>this._priv_onManifestReady(q,ee)),A.addEventListener("manifestUpdate",ee=>this._priv_onManifestUpdate(q,ee)),A.addEventListener("codecSupportUpdate",()=>this._priv_onCodecSupportUpdate(q)),A.addEventListener("decipherabilityUpdate",ee=>this._priv_onDecipherabilityUpdate(q,ee)),A.addEventListener("loaded",ee=>{this._priv_contentInfos!==null&&(this._priv_contentInfos.segmentSinkMetricsCallback=ee.getSegmentSinkMetrics,this._priv_contentInfos.fetchThumbnailDataCallback=ee.getThumbnailData)}),A.prepare(),this.stop();let X=Op(A,B,K,F,D.signal);D.signal.register(()=>{A.dispose()});let W=ee=>{switch(ee){case"STOPPED":case"RELOADING":case"LOADING":break;case"ENDED":this._priv_reloadingMetadata.reloadInPause=!0,this._priv_reloadingMetadata.reloadPosition=K.getReference().getValue().position.getPolled();break;default:{let ye=K.getReference().getValue();this._priv_reloadingMetadata.reloadInPause=ye.paused,this._priv_reloadingMetadata.reloadPosition=ye.position.getWanted();break}}},H=null,G=ee=>{H!==null&&(H.cancel(),H=null),X.onUpdate((ye,ot)=>{yr(ye)&&(ot(),H!==null&&H.cancel(),H=new U,H.linkToSignal(D.signal),ee!==!B.paused&&(B.paused?this.trigger("pause",null):this.trigger("play",null)),wp(B,()=>this.trigger("play",null),()=>this.trigger("pause",null),D.signal))},{emitCurrentValue:!1,clearSignal:D.signal})};G(t),A.addEventListener("reloadingMediaSource",ee=>{G(ee.autoPlay)}),this._priv_currentError=null,this._priv_contentInfos=q;let ie=null;X.onUpdate(ee=>{W(ee),this._priv_setPlayerState(ee),!D.isUsed()&&(ie!==null?yr(this.state)||(ie.cancel(),ie=null):yr(this.state)&&(ie=new U,ie.linkToSignal(D.signal),xp(K,()=>this.trigger("seeking",null),()=>this.trigger("seeked",null),ie.signal)))},{emitCurrentValue:!0,clearSignal:D.signal}),K.listen(ee=>{W(this.state),this._priv_triggerPositionUpdate(q,ee)},{clearSignal:D.signal}),D.signal.register(()=>{A.removeEventListener()}),this._priv_contentLock.onUpdate((ee,ye)=>{ee||(ye(),A.start(B,K))},{emitCurrentValue:!0,clearSignal:D.signal})}getError(){return this._priv_currentError}getVideoElement(){return this.videoElement}getPlayerState(){return this.state}isContentLoaded(){return!$(["LOADING","RELOADING","STOPPED"],this.state)}isBuffering(){return $(["BUFFERING","SEEKING","LOADING","RELOADING"],this.state)}isPaused(){return this.videoElement!==null?$(["LOADING","RELOADING"],this.state)?!this._priv_lastAutoPlay:this.videoElement.paused:!0}isLive(){if(this._priv_contentInfos===null)return!1;let{isDirectFile:e,manifest:t}=this._priv_contentInfos;return e||t===null?!1:t.isLive}areTrickModeTracksEnabled(){return this._priv_preferTrickModeTracks}getContentUrls(){if(this._priv_contentInfos===null)return;let{isDirectFile:e,manifest:t,originalUrl:r}=this._priv_contentInfos;if(e)return r===void 0?void 0:[r];if(t!==null)return t.uris}updateContentUrls(e,t){if(this._priv_contentInfos===null)throw new Error("No content loaded");let r=(t==null?void 0:t.refresh)===!0;this._priv_contentInfos.initializer.updateContentUrls(e,r)}getMediaDuration(){if(this.videoElement===null)throw new Error("Disposed player");return this.videoElement.duration}getCurrentBufferGap(){if(this.videoElement===null)throw new Error("Disposed player");let e=this.videoElement,t=pc(e.buffered,e.currentTime);return t===1/0?0:t}getWallClockTime(){if(this.videoElement===null)throw new Error("Disposed player");if(this._priv_contentInfos===null)return this.videoElement.currentTime;let e=this.getWallClockOffset();return this.videoElement.currentTime+e}getWallClockOffset(){var r;if(this.videoElement===null||this._priv_contentInfos===null)return 0;let{isDirectFile:e,manifest:t}=this._priv_contentInfos;if(e){let i=yo(this.videoElement);return i!=null?i:0}return t!==null&&(r=t.availabilityStartTime)!=null?r:0}getPosition(){if(this.videoElement===null)throw new Error("Disposed player");return this.videoElement.currentTime}getLastStoredContentPosition(){return this._priv_reloadingMetadata.reloadPosition}getPlaybackRate(){return this._priv_speed.getValue()}setPlaybackRate(e,t){var o;e!==this._priv_speed.getValue()&&this._priv_speed.setValue(e);let r=t==null?void 0:t.preferTrickModeTracks;if(typeof r!="boolean")return;this._priv_preferTrickModeTracks=r;let i=(o=this._priv_contentInfos)==null?void 0:o.tracksStore;E(i)||(r&&!i.isTrickModeEnabled()?i.enableVideoTrickModeTracks():!r&&i.isTrickModeEnabled()&&i.disableVideoTrickModeTracks())}getVideoRepresentation(){let e=this.__priv_getCurrentRepresentations();if(e!==null)return E(e.video)?e.video:In(e.video)}getAudioRepresentation(){let e=this.__priv_getCurrentRepresentations();if(e!==null)return E(e.audio)?e.video:Bo(e.audio)}play(){if(this.videoElement===null)throw new Error("Disposed player");let e=this.videoElement.play();return E(e)||typeof e.catch!="function"?Promise.resolve():e.catch(t=>{if(t.name==="NotAllowedError"){let r=new re("MEDIA_ERR_PLAY_NOT_ALLOWED",t.toString());this.trigger("warning",r)}throw t})}pause(){if(this.videoElement===null)throw new Error("Disposed player");this.videoElement.pause()}seekTo(e){var o;if(this.videoElement===null)throw new Error("Disposed player");if(this._priv_contentInfos===null)throw new Error("player: no content loaded");let{isDirectFile:t,manifest:r}=this._priv_contentInfos,i;if(typeof e=="number")i=e;else if(typeof e=="object"){let a=e,s=this.videoElement.currentTime;if(!E(a.relative))i=s+a.relative;else if(!E(a.position))i=a.position;else{if(E(a.wallClockTime))throw new Error('invalid time object. You must set one of the following properties: "relative", "position" or "wallClockTime"');if(r!==null)i=a.wallClockTime-((o=r.availabilityStartTime)!=null?o:0);else if(t){if(this.videoElement!==null){let d=yo(this.videoElement);d!==void 0&&(i=a.wallClockTime-d)}}else throw new Error("Cannot seek: wallClockTime asked but Manifest not yet loaded.");i===void 0&&(i=a.wallClockTime)}}if(i===void 0)throw new Error("invalid time given");return m.info("API","API seekTo",{positionWanted:i}),this._priv_contentInfos.playbackObserver.setCurrentTime(i,!1),i}getVolume(){if(this.videoElement===null)throw new Error("Disposed player");return this.videoElement.volume}setVolume(e){if(this.videoElement===null)throw new Error("Disposed player");let t=this.videoElement;e!==t.volume&&(t.volume=e)}isMute(){var e;return((e=this.videoElement)==null?void 0:e.muted)===!0}mute(){if(this.videoElement===null)throw new Error("Disposed player");this.videoElement.muted||(this.videoElement.muted=!0)}unMute(){if(this.videoElement===null)throw new Error("Disposed player");this.videoElement.muted&&(this.videoElement.muted=!1)}setMaxBufferBehind(e){this._priv_bufferOptions.maxBufferBehind.setValue(e)}setMaxBufferAhead(e){this._priv_bufferOptions.maxBufferAhead.setValue(e)}setWantedBufferAhead(e){this._priv_bufferOptions.wantedBufferAhead.setValue(e)}setMaxVideoBufferSize(e){this._priv_bufferOptions.maxVideoBufferSize.setValue(e)}getMaxBufferBehind(){return this._priv_bufferOptions.maxBufferBehind.getValue()}getMaxBufferAhead(){return this._priv_bufferOptions.maxBufferAhead.getValue()}getWantedBufferAhead(){return this._priv_bufferOptions.wantedBufferAhead.getValue()}getMaxVideoBufferSize(){return this._priv_bufferOptions.maxVideoBufferSize.getValue()}getCurrentPeriod(){var t;let e=(t=this._priv_contentInfos)==null?void 0:t.currentPeriod;return E(e)?null:{id:e.id,start:e.start,end:e.end}}getKeySystemConfiguration(){if(this.videoElement===null)throw new Error("Disposed player");let e=Zn(this.videoElement);return e===null?null:{keySystem:e[0],configuration:e[1]}}getAvailablePeriods(){if(this._priv_contentInfos===null)return[];let{isDirectFile:e,tracksStore:t}=this._priv_contentInfos;return e?[]:t===null?[]:t.getAvailablePeriods().slice()}getAvailableAudioTracks(e){var a,s;if(this._priv_contentInfos===null)return[];let{isDirectFile:t,mediaElementTracksStore:r}=this._priv_contentInfos;if(t)return(a=r==null?void 0:r.getAvailableAudioTracks())!=null?a:[];let i,o=!0;return typeof e=="string"?i=e:(i=e==null?void 0:e.periodId,o=(s=e==null?void 0:e.filterPlayableRepresentations)!=null?s:!0),this._priv_callTracksStoreGetterSetter(i,[],(d,u)=>{var c;return(c=d.getAvailableAudioTracks(u,o))!=null?c:[]})}getAvailableTextTracks(e){var i;if(this._priv_contentInfos===null)return[];let{isDirectFile:t,mediaElementTracksStore:r}=this._priv_contentInfos;return t?(i=r==null?void 0:r.getAvailableTextTracks())!=null?i:[]:this._priv_callTracksStoreGetterSetter(e,[],(o,a)=>{var s;return(s=o.getAvailableTextTracks(a))!=null?s:[]})}getAvailableVideoTracks(e){var a,s;if(this._priv_contentInfos===null)return[];let{isDirectFile:t,mediaElementTracksStore:r}=this._priv_contentInfos;if(t)return(a=r==null?void 0:r.getAvailableVideoTracks())!=null?a:[];let i,o=!0;return typeof e=="string"?i=e:(i=e==null?void 0:e.periodId,o=(s=e==null?void 0:e.filterPlayableRepresentations)!=null?s:!0),this._priv_callTracksStoreGetterSetter(i,[],(d,u)=>{var c;return(c=d.getAvailableVideoTracks(u,o))!=null?c:[]})}getAudioTrack(e){var a;if(this._priv_contentInfos===null)return;let{isDirectFile:t,mediaElementTracksStore:r}=this._priv_contentInfos;if(t)return r===null?void 0:r.getChosenAudioTrack();let i,o=!0;return typeof e=="string"?i=e:(i=e==null?void 0:e.periodId,o=(a=e==null?void 0:e.filterPlayableRepresentations)!=null?a:!0),this._priv_callTracksStoreGetterSetter(i,void 0,(s,d)=>s.getChosenAudioTrack(d,o))}getTextTrack(e){if(this._priv_contentInfos===null)return;let{isDirectFile:t,mediaElementTracksStore:r}=this._priv_contentInfos;return t?r===null?void 0:r.getChosenTextTrack():this._priv_callTracksStoreGetterSetter(e,void 0,(i,o)=>i.getChosenTextTrack(o))}getVideoTrack(e){var a;if(this._priv_contentInfos===null)return;let{isDirectFile:t,mediaElementTracksStore:r}=this._priv_contentInfos;if(t)return r===null?void 0:r.getChosenVideoTrack();let i,o=!0;return typeof e=="string"?i=e:(i=e==null?void 0:e.periodId,o=(a=e==null?void 0:e.filterPlayableRepresentations)!=null?a:!0),this._priv_callTracksStoreGetterSetter(i,void 0,(s,d)=>s.getChosenVideoTrack(d,o))}setAudioTrack(e){var u;if(this._priv_contentInfos===null)throw new Error("No content loaded");let{isDirectFile:t,mediaElementTracksStore:r}=this._priv_contentInfos;if(t)try{let c=typeof e=="string"?e:e.trackId;r==null||r.setAudioTrackById(c);return}catch(c){throw new Error("player: unknown audio track")}let i,o,a,s=null,d;return typeof e=="string"?o=e:(o=e.trackId,i=e.periodId,a=e.switchingMode,s=(u=e.lockedRepresentations)!=null?u:null,d=e.relativeResumingPosition),this._priv_callTracksStoreGetterSetter(i,void 0,(c,l)=>c.setAudioTrack({periodRef:l,trackId:o,switchingMode:a,lockedRepresentations:s,relativeResumingPosition:d}))}setTextTrack(e){if(this._priv_contentInfos===null)throw new Error("No content loaded");let{isDirectFile:t,mediaElementTracksStore:r}=this._priv_contentInfos;if(t)try{let a=typeof e=="string"?e:e.trackId;r==null||r.setTextTrackById(a);return}catch(a){throw new Error("player: unknown text track")}let i,o;return typeof e=="string"?o=e:(o=e.trackId,i=e.periodId),this._priv_callTracksStoreGetterSetter(i,void 0,(a,s)=>a.setTextTrack(s,o))}disableTextTrack(e){if(this._priv_contentInfos===null)return;let{isDirectFile:t,mediaElementTracksStore:r}=this._priv_contentInfos;if(t){r==null||r.disableTextTrack();return}return this._priv_callTracksStoreGetterSetter(e,void 0,(i,o)=>i.disableTrack(o,"text"))}setVideoTrack(e){var u;if(this._priv_contentInfos===null)throw new Error("No content loaded");let{isDirectFile:t,mediaElementTracksStore:r}=this._priv_contentInfos;if(t)try{let c=typeof e=="string"?e:e.trackId;r==null||r.setVideoTrackById(c);return}catch(c){throw new Error("player: unknown video track")}let i,o,a,s=null,d;return typeof e=="string"?o=e:(o=e.trackId,i=e.periodId,a=e.switchingMode,s=(u=e.lockedRepresentations)!=null?u:null,d=e.relativeResumingPosition),this._priv_callTracksStoreGetterSetter(i,void 0,(c,l)=>c.setVideoTrack({periodRef:l,trackId:o,switchingMode:a,lockedRepresentations:s,relativeResumingPosition:d}))}disableVideoTrack(e){if(this._priv_contentInfos===null)return;let{isDirectFile:t,mediaElementTracksStore:r}=this._priv_contentInfos;return t&&r!==null?r.disableVideoTrack():this._priv_callTracksStoreGetterSetter(e,void 0,(i,o)=>i.disableTrack(o,"video"))}lockVideoRepresentations(e){if(this._priv_contentInfos===null)throw new Error("No content loaded");let{isDirectFile:t}=this._priv_contentInfos;if(t)throw new Error("Cannot lock video Representations in directfile mode.");let r,i,o;return Array.isArray(e)?(r=e,i=void 0):(r=e.representations,i=e.periodId,o=e.switchingMode),this._priv_callTracksStoreGetterSetter(i,void 0,(a,s)=>a.lockVideoRepresentations(s,{representations:r,switchingMode:o}))}disableAudioTrack(e){if(this._priv_contentInfos===null)return;let{isDirectFile:t,mediaElementTracksStore:r}=this._priv_contentInfos;return t&&r!==null?r.disableAudioTrack():this._priv_callTracksStoreGetterSetter(e,void 0,(i,o)=>i.disableTrack(o,"audio"))}lockAudioRepresentations(e){if(this._priv_contentInfos===null)throw new Error("No content loaded");let{isDirectFile:t}=this._priv_contentInfos;if(t)throw new Error("Cannot lock audio Representations in directfile mode.");let r,i,o;return Array.isArray(e)?(r=e,i=void 0):(r=e.representations,i=e.periodId,o=e.switchingMode),this._priv_callTracksStoreGetterSetter(i,void 0,(a,s)=>a.lockAudioRepresentations(s,{representations:r,switchingMode:o}))}getLockedVideoRepresentations(e){if(this._priv_contentInfos===null)return null;let{isDirectFile:t}=this._priv_contentInfos;return t?null:this._priv_callTracksStoreGetterSetter(e,null,(r,i)=>r.getLockedVideoRepresentations(i))}getLockedAudioRepresentations(e){if(this._priv_contentInfos===null)return null;let{isDirectFile:t}=this._priv_contentInfos;return t?null:this._priv_callTracksStoreGetterSetter(e,null,(r,i)=>r.getLockedAudioRepresentations(i))}unlockVideoRepresentations(e){if(this._priv_contentInfos===null)return;let{isDirectFile:t}=this._priv_contentInfos;if(!t)return this._priv_callTracksStoreGetterSetter(e,void 0,(r,i)=>r.unlockVideoRepresentations(i))}unlockAudioRepresentations(e){if(this._priv_contentInfos===null)return;let{isDirectFile:t}=this._priv_contentInfos;if(!t)return this._priv_callTracksStoreGetterSetter(e,void 0,(r,i)=>r.unlockAudioRepresentations(i))}getMinimumPosition(){if(this._priv_contentInfos===null)return null;if(this._priv_contentInfos.isDirectFile)return 0;let{manifest:e}=this._priv_contentInfos;return e!==null?bn(e):null}getLivePosition(){if(this._priv_contentInfos===null)return null;let{isDirectFile:e,manifest:t}=this._priv_contentInfos;if(!e)return(t==null?void 0:t.isLive)!==!0?null:Sn(t)}getMaximumPosition(){if(this._priv_contentInfos===null)return null;let{isDirectFile:e,manifest:t}=this._priv_contentInfos;if(e){if(this.videoElement===null)throw new Error("Disposed player");return this.videoElement.duration}return t!==null?!t.isDynamic&&this.videoElement!==null?this.videoElement.duration:kt(t):null}async __priv_getSegmentSinkMetrics(){var e,t;return(t=(e=this._priv_contentInfos)==null?void 0:e.segmentSinkMetricsCallback)==null?void 0:t.call(e)}__priv_getManifest(){return this._priv_contentInfos===null?null:this._priv_contentInfos.manifest}__priv_getCurrentAdaptation(){if(this._priv_contentInfos===null)return null;let{currentPeriod:e,activeAdaptations:t}=this._priv_contentInfos;return e===null||t===null||E(t[e.id])?null:t[e.id]}__priv_getCurrentRepresentations(){if(this._priv_contentInfos===null)return null;let{currentPeriod:e,activeRepresentations:t}=this._priv_contentInfos;return e===null||t===null||E(t[e.id])?null:t[e.id]}_priv_cleanUpCurrentContentState(){var t,r,i,o;m.debug("API","Locking `contentLock` to clean-up the current content."),this._priv_contentLock.setValue(!0),(r=(t=this._priv_contentInfos)==null?void 0:t.tracksStore)==null||r.dispose(),(o=(i=this._priv_contentInfos)==null?void 0:i.mediaElementTracksStore)==null||o.dispose(),this._priv_contentInfos=null,this._priv_contentEventsMemory={};let e=()=>{this.videoElement!==null&&(m.debug("API","Unlocking `contentLock`. Next content can begin."),this._priv_contentLock.setValue(!1))};E(this.videoElement)?e():zo(this.videoElement).then(()=>{m.debug("API","DRM session cleaned-up with success!"),e()},a=>{m.error("API","An error arised when trying to clean-up the DRM session:"+(a instanceof Error?a.toString():"Unknown Error")),e()})}_priv_onManifestReady(e,t){var i;if(e.contentId!==((i=this._priv_contentInfos)==null?void 0:i.contentId))return;e.manifest=t,t.manifestFormat===0&&(this._priv_reloadingMetadata.manifest=t);let r=new Pp({preferTrickModeTracks:this._priv_preferTrickModeTracks,defaultAudioTrackSwitchingMode:e.defaultAudioTrackSwitchingMode,onTracksNotPlayableForType:{audio:e.onAudioTracksNotPlayable,video:e.onVideoTracksNotPlayable,text:"continue"}});e.tracksStore=r,r.addEventListener("newAvailablePeriods",o=>{this.trigger("newAvailablePeriods",o)}),r.addEventListener("brokenRepresentationsLock",o=>{this.trigger("brokenRepresentationsLock",o)}),r.addEventListener("trackUpdate",o=>{var s,d;this.trigger("trackUpdate",o);let a=(d=(s=this._priv_contentInfos)==null?void 0:s.currentPeriod)!=null?d:void 0;o.reason==="no-playable-representation"&&o.period.id===(a==null?void 0:a.id)&&this._priv_onAvailableTracksMayHaveChanged(o.trackType)}),r.addEventListener("warning",o=>{this.trigger("warning",o)}),r.addEventListener("error",o=>{this._priv_onFatalError(o,e)}),r.addEventListener("noPlayableTrack",o=>{this.trigger("noPlayableTrack",o)}),r.onManifestUpdate(t)}_priv_onManifestUpdate(e,t){var o,a,s;if(this._priv_contentInfos===null||this._priv_contentInfos.manifest===null)return;E(e==null?void 0:e.tracksStore)||e.tracksStore.onManifestUpdate(this._priv_contentInfos.manifest);let r=(a=(o=this._priv_contentInfos)==null?void 0:o.currentPeriod)!=null?a:void 0,i=(s=this._priv_contentInfos)==null?void 0:s.tracksStore;if(!(r===void 0||E(i))){for(let d of t.updatedPeriods)if(d.period.id===r.id&&(d.result.addedAdaptations.length>0||d.result.removedAdaptations.length>0)){if(i.getPeriodObjectFromPeriod(r)===void 0)return;this._priv_onAvailableTracksMayHaveChanged("audio"),this._priv_onAvailableTracksMayHaveChanged("text"),this._priv_onAvailableTracksMayHaveChanged("video")}}}_priv_onCodecSupportUpdate(e){let t=e==null?void 0:e.tracksStore;E(t)||t.onManifestCodecSupportUpdate()}_priv_onDecipherabilityUpdate(e,t){if(e===null||e.manifest===null)return;E(e==null?void 0:e.tracksStore)||e.tracksStore.onDecipherabilityUpdates();let r=t.reduce((i,o)=>{var s,d,u;if(!(Q(i,c=>c[0].id===o.period.id&&c[1]===o.adaptation.type)!==void 0)){let c=e.tracksStore;if(c===null)return i;let l=!1,f=c.getPeriodObjectFromPeriod(o.period);if(f===void 0)return i;switch(o.adaptation.type){case"audio":l=((s=c.getChosenAudioTrack(f,!1))==null?void 0:s.id)===o.adaptation.id;break;case"video":l=((d=c.getChosenVideoTrack(f,!1))==null?void 0:d.id)===o.adaptation.id;break;case"text":l=((u=c.getChosenTextTrack(f))==null?void 0:u.id)===o.adaptation.id;break}l&&i.push([o.period,o.adaptation.type])}return i},[]);for(let[i,o]of r)this._priv_triggerEventIfNotStopped("representationListUpdate",{period:{start:i.start,end:i.end,id:i.id},trackType:o,reason:"decipherability-update"},e.currentContentCanceller.signal)}_priv_onActivePeriodChanged(e,{period:t}){var s,d,u,c,l,f;if(e.contentId!==((s=this._priv_contentInfos)==null?void 0:s.contentId))return;e.currentPeriod=t;let r=e.currentContentCanceller.signal;this._priv_contentEventsMemory.periodChange!==t&&(this._priv_contentEventsMemory.periodChange=t,this._priv_triggerEventIfNotStopped("periodChange",{start:t.start,end:t.end,id:t.id},r)),this._priv_triggerEventIfNotStopped("availableAudioTracksChange",this.getAvailableAudioTracks(),r),this._priv_triggerEventIfNotStopped("availableTextTracksChange",this.getAvailableTextTracks(),r),this._priv_triggerEventIfNotStopped("availableVideoTracksChange",this.getAvailableVideoTracks(),r);let i=(d=this._priv_contentInfos)==null?void 0:d.tracksStore;if(E(i))this._priv_triggerEventIfNotStopped("audioTrackChange",null,r),this._priv_triggerEventIfNotStopped("textTrackChange",null,r),this._priv_triggerEventIfNotStopped("videoTrackChange",null,r);else{let p=i.getPeriodObjectFromPeriod(t);if(p!==void 0){let h=i.getChosenAudioTrack(p,!0);this._priv_triggerEventIfNotStopped("audioTrackChange",h,r);let I=i.getChosenTextTrack(p);this._priv_triggerEventIfNotStopped("textTrackChange",I,r);let g=i.getChosenVideoTrack(p,!0);this._priv_triggerEventIfNotStopped("videoTrackChange",g,r)}}let o=(c=(u=this.__priv_getCurrentRepresentations())==null?void 0:u.audio)!=null?c:null;this._priv_triggerEventIfNotStopped("audioRepresentationChange",E(o)?o:In(o),r);let a=(f=(l=this.__priv_getCurrentRepresentations())==null?void 0:l.video)!=null?f:null;this._priv_triggerEventIfNotStopped("videoRepresentationChange",E(a)?a:In(a),r)}_priv_onPeriodStreamReady(e,t){var s;if(e.contentId!==((s=this._priv_contentInfos)==null?void 0:s.contentId))return;let{type:r,period:i,adaptationRef:o}=t,a=e.tracksStore;switch(r){case"video":case"audio":case"text":E(a)?(m.error("API",`TracksStore not instanciated for a new ${r} period`),o.setValue(null)):a.addTrackReference(r,i,o);break;default:ze(r)}}_priv_onPeriodStreamCleared(e,t){var d;if(e.contentId!==((d=this._priv_contentInfos)==null?void 0:d.contentId))return;let{type:r,periodId:i}=t,o=e.tracksStore;switch(r){case"audio":case"text":case"video":E(o)||o.removeTrackReference(r,i);break}let{activeAdaptations:a,activeRepresentations:s}=e;if(!E(a)&&!E(a[i])){let u=a[i];delete u[r],Object.keys(u).length===0&&delete a[i]}if(!E(s)&&!E(s[i])){let u=s[i];delete u[r],Object.keys(u).length===0&&delete s[i]}}_priv_onAdaptationChange(e,{type:t,adaptation:r,period:i}){var c;if(e.contentId!==((c=this._priv_contentInfos)==null?void 0:c.contentId))return;e.activeAdaptations===null&&(e.activeAdaptations={});let{activeAdaptations:o,currentPeriod:a}=e,s=o[i.id];E(s)?o[i.id]={[t]:r}:s[t]=r;let{tracksStore:d}=e,u=e.currentContentCanceller.signal;if(d!==null&&a!==null&&!E(i)&&i.id===a.id){let l=d.getPeriodObjectFromPeriod(i);if(l===void 0)return;switch(t){case"audio":{let f=d.getChosenAudioTrack(l,!0);this._priv_triggerEventIfNotStopped("audioTrackChange",f,u);break}case"text":{let f=d.getChosenTextTrack(l);this._priv_triggerEventIfNotStopped("textTrackChange",f,u);break}case"video":{let f=d.getChosenVideoTrack(l,!0);this._priv_triggerEventIfNotStopped("videoTrackChange",f,u);break}}}}_priv_onRepresentationChange(e,{type:t,period:r,representation:i}){var d;if(e.contentId!==((d=this._priv_contentInfos)==null?void 0:d.contentId))return;e.activeRepresentations===null&&(e.activeRepresentations={});let{activeRepresentations:o,currentPeriod:a}=e,s=o[r.id];if(E(s)?o[r.id]={[t]:i}:s[t]=i,!E(r)&&a!==null&&a.id===r.id){let u=this._priv_contentInfos.currentContentCanceller.signal;t==="video"?this._priv_triggerEventIfNotStopped("videoRepresentationChange",E(i)?i:In(i),u):t==="audio"&&this._priv_triggerEventIfNotStopped("audioRepresentationChange",E(i)?i:Bo(i),u)}}_priv_onBitrateEstimateChange({type:e,bitrate:t}){t!==void 0&&(this._priv_bitrateInfos.lastBitrates[e]=t),this.trigger("__priv_bitrateEstimateChange",{type:e,bitrate:t})}_priv_setPlayerState(e){this.state!==e&&(this.state=e,m.info("API","playerStateChange event",{newState:e}),this.trigger("playerStateChange",e))}_priv_triggerPositionUpdate(e,t){var s,d;if(e.contentId!==((s=this._priv_contentInfos)==null?void 0:s.contentId))return;let{isDirectFile:r,manifest:i}=e;if(!r&&i===null||E(t))return;let o=i!==null?kt(i):void 0,a={position:t.position.getPolled(),duration:t.duration,playbackRate:t.playbackRate,maximumPosition:o,bufferGap:t.bufferGap===void 0||!isFinite(t.bufferGap)?0:t.bufferGap};if(i!==null&&i.isLive&&t.position.getPolled()>0){let u=(d=i.availabilityStartTime)!=null?d:0;a.wallClockTime=t.position.getPolled()+u;let c=Sn(i);c!==void 0&&(a.liveGap=c-t.position.getPolled())}else if(r&&this.videoElement!==null){let u=yo(this.videoElement);u!==void 0&&(a.wallClockTime=u+t.position.getPolled())}this.trigger("positionUpdate",a)}_priv_triggerEventIfNotStopped(e,t,r){r.isCancelled()||this.trigger(e,t)}_priv_initializeMediaElementTracksStore(e){var r,i,o;ne(pe.directfile!==null,"Initializing `MediaElementTracksStore` without Directfile feature"),ne(this.videoElement!==null,"Initializing `MediaElementTracksStore` on a disposed RxPlayer");let t=new pe.directfile.mediaElementTracksStore(this.videoElement);return this._priv_triggerEventIfNotStopped("availableAudioTracksChange",t.getAvailableAudioTracks(),e),this._priv_triggerEventIfNotStopped("availableVideoTracksChange",t.getAvailableVideoTracks(),e),this._priv_triggerEventIfNotStopped("availableTextTracksChange",t.getAvailableTextTracks(),e),this._priv_triggerEventIfNotStopped("audioTrackChange",(r=t.getChosenAudioTrack())!=null?r:null,e),this._priv_triggerEventIfNotStopped("textTrackChange",(i=t.getChosenTextTrack())!=null?i:null,e),this._priv_triggerEventIfNotStopped("videoTrackChange",(o=t.getChosenVideoTrack())!=null?o:null,e),t.addEventListener("availableVideoTracksChange",a=>this.trigger("availableVideoTracksChange",a)),t.addEventListener("availableAudioTracksChange",a=>this.trigger("availableAudioTracksChange",a)),t.addEventListener("availableTextTracksChange",a=>this.trigger("availableTextTracksChange",a)),t.addEventListener("audioTrackChange",a=>this.trigger("audioTrackChange",a)),t.addEventListener("videoTrackChange",a=>this.trigger("videoTrackChange",a)),t.addEventListener("textTrackChange",a=>this.trigger("textTrackChange",a)),t}_priv_callTracksStoreGetterSetter(e,t,r){var d,u;if(this._priv_contentInfos===null||this._priv_contentInfos.tracksStore===null)return m.warn("API","Trying to call track API too soon"),t;let{tracksStore:i}=this._priv_contentInfos,o=(u=(d=this._priv_contentInfos)==null?void 0:d.currentPeriod)!=null?u:void 0,a=e!=null?e:o==null?void 0:o.id;if(a===void 0)return t;let s=a===(o==null?void 0:o.id)?i.getPeriodObjectFromPeriod(o):i.getPeriodObjectFromId(a);return s===void 0?t:r(i,s)}_priv_onAvailableTracksMayHaveChanged(e,t){let r=this._priv_contentInfos;if(r===null)return;let{currentPeriod:i,tracksStore:o,currentContentCanceller:a}=r,s=a.signal;if(E(i)||o===null)return;let d=t!=null?t:o.getPeriodObjectFromPeriod(i);if(d!==void 0)switch(e){case"video":{let u=o.getAvailableVideoTracks(d,!0);this._priv_triggerEventIfNotStopped("availableVideoTracksChange",u!=null?u:[],s);break}case"audio":{let u=o.getAvailableAudioTracks(d,!0);this._priv_triggerEventIfNotStopped("availableAudioTracksChange",u!=null?u:[],s);break}case"text":{let u=o.getAvailableTextTracks(d);this._priv_triggerEventIfNotStopped("availableTextTracksChange",u!=null?u:[],s);break}default:ze(e)}}_priv_onFatalError(e,t){let r=Me(e,{defaultCode:"NONE",defaultReason:"An unknown error stopped content playback."});r.fatal=!0,t.currentContentCanceller.cancel(),this._priv_cleanUpCurrentContentState(),this._priv_currentError=r,m.error("API","The player stopped because of an error",r),this._priv_setPlayerState("STOPPED"),this._priv_currentError===r&&this.trigger("error",r)}};Yt._priv_currentlyUsedVideoElements=new WeakSet;var Ir=Yt;Ir.version="4.4.0-dev.2025092200";var Dp=Ir;var es=Dp;ts();es.addFeatures([Fl,Au,Du,Lu,Cl,_l,Ml,Rl,ll,Ku,bl,Wu]);var nue=es;Z.RxPlayer=es;})();
23
+ Make sure to dispose the previous instance with player.dispose() before creating a new player instance attaching that video element.`),Yt._priv_currentlyUsedVideoElements.add(e)}static _priv_deregisterVideoElement(e){Yt._priv_currentlyUsedVideoElements.has(e)&&Yt._priv_currentlyUsedVideoElements.delete(e)}constructor(e={}){super();let{baseBandwidth:t,videoResolutionLimit:r,maxBufferAhead:i,maxBufferBehind:o,throttleVideoBitrateWhenHidden:a,videoElement:s,wantedBufferAhead:d,maxVideoBufferSize:u}=Cp(e);s.preload="auto",this.version="4.4.0-dev.2025092404",this.log=m,this.state="STOPPED",this.videoElement=s,Yt._priv_registerVideoElement(this.videoElement);let c=new U;this._destroyCanceller=c,this._priv_pictureInPictureRef=Lc(s,c.signal),this._priv_speed=new j(s.playbackRate,this._destroyCanceller.signal),this._priv_preferTrickModeTracks=!1,this._priv_contentLock=new j(!1,this._destroyCanceller.signal),this._priv_bufferOptions={wantedBufferAhead:new j(d,this._destroyCanceller.signal),maxBufferAhead:new j(i,this._destroyCanceller.signal),maxBufferBehind:new j(o,this._destroyCanceller.signal),maxVideoBufferSize:new j(u,this._destroyCanceller.signal)},this._priv_bitrateInfos={lastBitrates:{audio:t,video:t}},this._priv_throttleVideoBitrateWhenHidden=a,this._priv_videoResolutionLimit=r,this._priv_currentError=null,this._priv_contentInfos=null,this._priv_contentEventsMemory={},this._priv_reloadingMetadata={},this._priv_lastAutoPlay=!1,this._priv_worker=null;let l=()=>{this.trigger("volumeChange",{volume:s.volume,muted:s.muted})};s.addEventListener("volumechange",l),c.signal.register(()=>{s.removeEventListener("volumechange",l)})}attachWorker(e){return new Promise((t,r)=>{var a;if(!Vl())return m.warn("API","Cannot rely on a WebWorker: Worker API unavailable"),r(new mn("INCOMPATIBLE_ERROR","Worker unavailable"));if(this._priv_worker!==null){if(this.state!=="STOPPED")return m.warn("API","Cannot attach a new worker while a content is playing, please stop the player first."),r(new mn("SETUP_ERROR","Cannot attach a new worker while a content is playing"));this._priv_worker.terminate()}if(typeof e.workerUrl=="string")this._priv_worker=new Worker(e.workerUrl);else{let s=URL.createObjectURL(e.workerUrl);this._priv_worker=new Worker(s),URL.revokeObjectURL(s)}this._priv_worker.onerror=s=>{this._priv_worker!==null&&(this._priv_worker.terminate(),this._priv_worker=null),m.error("API","Unexpected worker error",s.error instanceof Error?s.error:void 0),r(new mn("UNKNOWN_ERROR",'Unexpected Worker "error" event'))};let i=s=>{let d=s.data;d.type==="init-error"?(m.warn("API","Processing InitError worker message: detaching worker"),this._priv_worker!==null&&(this._priv_worker.removeEventListener("message",i),this._priv_worker.terminate(),this._priv_worker=null),r(new mn("SETUP_ERROR","Worker parser initialization failed: "+d.value.errorMessage))):d.type==="init-success"&&(m.info("API","InitSuccess received from worker."),this._priv_worker!==null&&this._priv_worker.removeEventListener("message",i),t())};this._priv_worker.addEventListener("message",i),m.debug("M-->C","Sending message",{name:"init"}),this._priv_worker.postMessage({type:"init",value:{dashWasmUrl:e.dashWasmUrl,logLevel:m.getLevel(),logFormat:m.getFormat(),sendBackLogs:To,date:Date.now(),timestamp:z(),hasVideo:((a=this.videoElement)==null?void 0:a.nodeName.toLowerCase())==="video"}}),m.addEventListener("onLogLevelChange",s=>{this._priv_worker!==null&&(m.debug("M-->C","Sending message",{name:"log-level-update"}),this._priv_worker.postMessage({type:"log-level-update",value:{logLevel:s.level,logFormat:s.format,sendBackLogs:To}}))},this._destroyCanceller.signal);let o=s=>{this._priv_worker!==null&&(m.debug("M-->C","Sending message:",{name:"config-update"}),this._priv_worker.postMessage({type:"config-update",value:s}))};O.updated&&o(O.getCurrent()),O.addEventListener("update",o,this._destroyCanceller.signal)})}getCurrentModeInformation(){return this._priv_contentInfos===null?null:{isDirectFile:this._priv_contentInfos.isDirectFile,useWorker:this._priv_contentInfos.useWorker}}addEventListener(e,t){return super.addEventListener(e,t)}stop(){this._priv_contentInfos!==null&&this._priv_contentInfos.currentContentCanceller.cancel(),this._priv_cleanUpCurrentContentState(),this.state!=="STOPPED"&&this._priv_setPlayerState("STOPPED")}dispose(){this.stop(),this.videoElement!==null&&(Yt._priv_deregisterVideoElement(this.videoElement),qn(this.videoElement).catch(e=>{let t=e instanceof Error?e.message:"Unknown error";m.error("API","Could not dispose decryption resources: "+t)})),this._destroyCanceller.cancel(),this._priv_reloadingMetadata={},this.videoElement=null,this._priv_worker!==null&&(this._priv_worker.terminate(),this._priv_worker=null)}loadVideo(e){let t=Mp(e);m.info("API","Calling loadvideo",{url:t.url,transport:t.transport}),this._priv_reloadingMetadata={options:t},this._priv_initializeContentPlayback(t),this._priv_lastAutoPlay=t.autoPlay}reload(e){var c,l,f;let{options:t,manifest:r,reloadPosition:i,reloadInPause:o}=this._priv_reloadingMetadata;if(t===void 0)throw new Error("API: Can't reload without having previously loaded a content.");Ap(e);let a;if(((c=e==null?void 0:e.reloadAt)==null?void 0:c.position)!==void 0)a={position:e.reloadAt.position};else if(((l=e==null?void 0:e.reloadAt)==null?void 0:l.relative)!==void 0){if(i===void 0)throw new Error("Can't reload to a relative position when previous content was not loaded.");a={position:e.reloadAt.relative+i}}else i!==void 0&&(a={position:i});let s;(e==null?void 0:e.autoPlay)!==void 0?s=e.autoPlay:o!==void 0&&(s=!o);let d;(e==null?void 0:e.keySystems)!==void 0?d=e.keySystems:((f=this._priv_reloadingMetadata.options)==null?void 0:f.keySystems)!==void 0&&(d=this._priv_reloadingMetadata.options.keySystems);let u=ue(ae({},t),{initialManifest:r});a!==void 0&&(u.startAt=a),s!==void 0&&(u.autoPlay=s),d!==void 0&&(u.keySystems=d),this._priv_initializeContentPlayback(u)}createDebugElement(e){if(pe.createDebugElement===null)throw new Error("Feature `DEBUG_ELEMENT` not added to the RxPlayer");let t=new U;return pe.createDebugElement(e,this,t.signal),{dispose(){t.cancel()}}}getAvailableThumbnailTracks({time:e,periodId:t}={}){if(this._priv_contentInfos===null||this._priv_contentInfos.manifest===null)return[];let{manifest:r}=this._priv_contentInfos,i;if(e!==void 0){if(i=Hn(this._priv_contentInfos.manifest,e),i===void 0||i.thumbnailTracks.length===0)return[]}else if(t!==void 0){if(i=Q(r.periods,o=>o.id===t),i===void 0)return m.error("API","getAvailableThumbnailTracks: periodId not found",{periodId:t}),[]}else{let{currentPeriod:o}=this._priv_contentInfos;if(o===null)return[];i=o}return i.thumbnailTracks.map(o=>({id:o.id,width:Math.floor(o.width/o.horizontalTiles),height:Math.floor(o.height/o.verticalTiles),mimeType:o.mimeType}))}async renderThumbnail(e){if(E(e.time))throw new Error("You have to provide a `time` property to `renderThumbnail`, indicating the wanted thumbnail time in seconds.");if(E(e.container))throw new Error("You have to provide a `container` property to `renderThumbnail`, specifying the HTML Element in which the thumbnail should be inserted.");return zl(this._priv_contentInfos,e)}_priv_initializeContentPlayback(e){var oe,fe,Re,ge,he,_t;let{autoPlay:t,cmcd:r,defaultAudioTrackSwitchingMode:i,enableFastSwitching:o,initialManifest:a,keySystems:s,lowLatencyMode:d,minimumManifestUpdateInterval:u,requestConfig:c,onCodecSwitch:l,startAt:f,transport:p,checkMediaSegmentIntegrity:h,checkManifestIntegrity:I,manifestLoader:g,referenceDateTime:b,segmentLoader:T,serverSyncInfos:v,mode:_,experimentalOptions:R,__priv_manifestUpdateUrl:k,__priv_patchLastSegmentInSidx:x,url:P,onAudioTracksNotPlayable:M,onVideoTracksNotPlayable:L}=e;if(this.videoElement===null)throw new Error("the attached video element is disposed");let F=p==="directfile",D=new U,B=this.videoElement,A,C=!1,N=null;if(F){if(pe.directfile===null)throw this.stop(),this._priv_currentError=null,new Error("DirectFile feature not activated in your build.");if(E(P))throw new Error("No URL for a DirectFile content");if(m.info("API","Initializing DirectFile mode in the main thread"),N=this._priv_initializeMediaElementTracksStore(D.signal),D.isUsed())return;A=new pe.directfile.initDirectFile({autoPlay:t,keySystems:s,speed:this._priv_speed,startAt:f,url:P})}else{let ee={lowLatencyMode:d,maxRetry:(oe=c.manifest)==null?void 0:oe.maxRetry,requestTimeout:(fe=c.manifest)==null?void 0:fe.timeout,connectionTimeout:(Re=c.manifest)==null?void 0:Re.connectionTimeout,minimumManifestUpdateInterval:u,initialManifest:a},ye=Kl(),ot={throttleBitrate:{},limitResolution:{}};this._priv_throttleVideoBitrateWhenHidden&&(ye?ot.throttleBitrate={video:gn(Nc(this._priv_pictureInPictureRef,D.signal),Qt=>Qt?1/0:0,D.signal)}:m.warn("API","Can't apply throttleVideoBitrateWhenHidden because browser can't be trusted for visibility.")),this._priv_videoResolutionLimit==="videoElement"?ye?ot.limitResolution={video:Bc(B,this._priv_pictureInPictureRef,D.signal)}:m.warn("API","Can't apply videoResolutionLimit because browser can't be trusted for video size."):this._priv_videoResolutionLimit==="screen"&&(ot.limitResolution={video:Uc(D.signal)});let pn={initialBitrates:this._priv_bitrateInfos.lastBitrates,lowLatencyMode:d,throttlers:ot},ht=e.textTrackMode==="native"?{textTrackMode:"native"}:{textTrackMode:"html",textTrackElement:e.textTrackElement},yt=Y({enableFastSwitching:o,onCodecSwitch:l},this._priv_bufferOptions),Yl={lowLatencyMode:d,maxRetry:(ge=c.segment)==null?void 0:ge.maxRetry,requestTimeout:(he=c.segment)==null?void 0:he.timeout,connectionTimeout:(_t=c.segment)==null?void 0:_t.connectionTimeout},Lp=pe.multithread!==null&&this._priv_worker!==null&&this.videoElement.FORCED_MEDIA_SOURCE===void 0&&p==="dash"&&nS.every(Qt=>E(e[Qt]))&&typeof e.representationFilter!="function";if(_==="main"||_==="auto"&&!Lp){if(pe.mainThreadMediaSourceInit===null)throw new Error("Cannot load video, neither in a WebWorker nor with the `MEDIA_SOURCE_MAIN` feature");let Qt=pe.transports[p];if(typeof Qt!="function")throw this.stop(),this._priv_currentError=null,new Error(`transport "${p}" not supported`);let Np=typeof e.representationFilter=="string"?Mc(e.representationFilter):e.representationFilter;m.info("API","Initializing MediaSource mode in the main thread");let Up=Qt({lowLatencyMode:d,checkMediaSegmentIntegrity:h,checkManifestIntegrity:I,manifestLoader:g,referenceDateTime:b,representationFilter:Np,segmentLoader:T,serverSyncInfos:v,__priv_manifestUpdateUrl:k,__priv_patchLastSegmentInSidx:x});A=new pe.mainThreadMediaSourceInit({adaptiveOptions:pn,autoPlay:t,bufferOptions:yt,cmcd:r,enableRepresentationAvoidance:R.enableRepresentationAvoidance,keySystems:s,lowLatencyMode:d,transport:Up,manifestRequestSettings:ee,segmentRequestOptions:Yl,speed:this._priv_speed,startAt:f,textTrackOptions:ht,url:P})}else{if(pe.multithread===null)throw new Error("Cannot load video in multithread mode: `MULTI_THREAD` feature not imported.");if(this._priv_worker===null)throw new Error("Cannot load video in multithread mode: `attachWorker` method not called.");ne(typeof e.representationFilter!="function"),C=!0,m.info("API","Initializing MediaSource mode in a WebWorker");let Qt={lowLatencyMode:d,checkMediaSegmentIntegrity:h,checkManifestIntegrity:I,referenceDateTime:b,serverSyncInfos:v,manifestLoader:void 0,segmentLoader:void 0,representationFilter:e.representationFilter,__priv_manifestUpdateUrl:k,__priv_patchLastSegmentInSidx:x};A=new pe.multithread.init({adaptiveOptions:pn,autoPlay:t,bufferOptions:yt,cmcd:r,enableRepresentationAvoidance:R.enableRepresentationAvoidance,keySystems:s,lowLatencyMode:d,transportOptions:Qt,manifestRequestSettings:ee,segmentRequestOptions:Yl,speed:this._priv_speed,startAt:f,textTrackOptions:ht,worker:this._priv_worker,url:P,useMseInWorker:vm})}}let K=new Io(B,{withMediaSource:!F,lowLatencyMode:d});K.blockSeeking(),D.signal.register(()=>{K.stop()});let q={contentId:tS(),originalUrl:P,playbackObserver:K,currentContentCanceller:D,defaultAudioTrackSwitchingMode:i,initializer:A,isDirectFile:F,manifest:null,currentPeriod:null,activeAdaptations:null,activeRepresentations:null,tracksStore:null,mediaElementTracksStore:N,useWorker:C,segmentSinkMetricsCallback:null,fetchThumbnailDataCallback:null,thumbnailRequestsInfo:{pendingRequests:new WeakMap,lastResponse:null},onAudioTracksNotPlayable:M,onVideoTracksNotPlayable:L};A.addEventListener("error",ee=>{this._priv_onFatalError(ee,q)}),A.addEventListener("warning",ee=>{let ye=Me(ee,{defaultCode:"NONE",defaultReason:"An unknown error happened."});m.warn("API","Sending warning:",ye),this.trigger("warning",ye)}),A.addEventListener("reloadingMediaSource",ee=>{q.tracksStore!==null&&q.tracksStore.resetPeriodObjects(),this._priv_contentInfos!==null&&(this._priv_contentInfos.segmentSinkMetricsCallback=null),this._priv_lastAutoPlay=ee.autoPlay}),A.addEventListener("inbandEvents",ee=>this.trigger("inbandEvents",ee)),A.addEventListener("streamEvent",ee=>this.trigger("streamEvent",ee)),A.addEventListener("streamEventSkip",ee=>this.trigger("streamEventSkip",ee)),A.addEventListener("activePeriodChanged",ee=>this._priv_onActivePeriodChanged(q,ee)),A.addEventListener("periodStreamReady",ee=>this._priv_onPeriodStreamReady(q,ee)),A.addEventListener("periodStreamCleared",ee=>this._priv_onPeriodStreamCleared(q,ee)),A.addEventListener("representationChange",ee=>this._priv_onRepresentationChange(q,ee)),A.addEventListener("adaptationChange",ee=>this._priv_onAdaptationChange(q,ee)),A.addEventListener("bitrateEstimateChange",ee=>this._priv_onBitrateEstimateChange(ee)),A.addEventListener("manifestReady",ee=>this._priv_onManifestReady(q,ee)),A.addEventListener("manifestUpdate",ee=>this._priv_onManifestUpdate(q,ee)),A.addEventListener("codecSupportUpdate",()=>this._priv_onCodecSupportUpdate(q)),A.addEventListener("decipherabilityUpdate",ee=>this._priv_onDecipherabilityUpdate(q,ee)),A.addEventListener("loaded",ee=>{this._priv_contentInfos!==null&&(this._priv_contentInfos.segmentSinkMetricsCallback=ee.getSegmentSinkMetrics,this._priv_contentInfos.fetchThumbnailDataCallback=ee.getThumbnailData)}),A.prepare(),this.stop();let X=Op(A,B,K,F,D.signal);D.signal.register(()=>{A.dispose()});let W=ee=>{switch(ee){case"STOPPED":case"RELOADING":case"LOADING":break;case"ENDED":this._priv_reloadingMetadata.reloadInPause=!0,this._priv_reloadingMetadata.reloadPosition=K.getReference().getValue().position.getPolled();break;default:{let ye=K.getReference().getValue();this._priv_reloadingMetadata.reloadInPause=ye.paused,this._priv_reloadingMetadata.reloadPosition=ye.position.getWanted();break}}},H=null,G=ee=>{H!==null&&(H.cancel(),H=null),X.onUpdate((ye,ot)=>{yr(ye)&&(ot(),H!==null&&H.cancel(),H=new U,H.linkToSignal(D.signal),ee!==!B.paused&&(B.paused?this.trigger("pause",null):this.trigger("play",null)),wp(B,()=>this.trigger("play",null),()=>this.trigger("pause",null),D.signal))},{emitCurrentValue:!1,clearSignal:D.signal})};G(t),A.addEventListener("reloadingMediaSource",ee=>{G(ee.autoPlay)}),this._priv_currentError=null,this._priv_contentInfos=q;let ie=null;X.onUpdate(ee=>{W(ee),this._priv_setPlayerState(ee),!D.isUsed()&&(ie!==null?yr(this.state)||(ie.cancel(),ie=null):yr(this.state)&&(ie=new U,ie.linkToSignal(D.signal),xp(K,()=>this.trigger("seeking",null),()=>this.trigger("seeked",null),ie.signal)))},{emitCurrentValue:!0,clearSignal:D.signal}),K.listen(ee=>{W(this.state),this._priv_triggerPositionUpdate(q,ee)},{clearSignal:D.signal}),D.signal.register(()=>{A.removeEventListener()}),this._priv_contentLock.onUpdate((ee,ye)=>{ee||(ye(),A.start(B,K))},{emitCurrentValue:!0,clearSignal:D.signal})}getError(){return this._priv_currentError}getVideoElement(){return this.videoElement}getPlayerState(){return this.state}isContentLoaded(){return!$(["LOADING","RELOADING","STOPPED"],this.state)}isBuffering(){return $(["BUFFERING","SEEKING","LOADING","RELOADING"],this.state)}isPaused(){return this.videoElement!==null?$(["LOADING","RELOADING"],this.state)?!this._priv_lastAutoPlay:this.videoElement.paused:!0}isLive(){if(this._priv_contentInfos===null)return!1;let{isDirectFile:e,manifest:t}=this._priv_contentInfos;return e||t===null?!1:t.isLive}areTrickModeTracksEnabled(){return this._priv_preferTrickModeTracks}getContentUrls(){if(this._priv_contentInfos===null)return;let{isDirectFile:e,manifest:t,originalUrl:r}=this._priv_contentInfos;if(e)return r===void 0?void 0:[r];if(t!==null)return t.uris}updateContentUrls(e,t){if(this._priv_contentInfos===null)throw new Error("No content loaded");let r=(t==null?void 0:t.refresh)===!0;this._priv_contentInfos.initializer.updateContentUrls(e,r)}getMediaDuration(){if(this.videoElement===null)throw new Error("Disposed player");return this.videoElement.duration}getCurrentBufferGap(){if(this.videoElement===null)throw new Error("Disposed player");let e=this.videoElement,t=pc(e.buffered,e.currentTime);return t===1/0?0:t}getWallClockTime(){if(this.videoElement===null)throw new Error("Disposed player");if(this._priv_contentInfos===null)return this.videoElement.currentTime;let e=this.getWallClockOffset();return this.videoElement.currentTime+e}getWallClockOffset(){var r;if(this.videoElement===null||this._priv_contentInfos===null)return 0;let{isDirectFile:e,manifest:t}=this._priv_contentInfos;if(e){let i=yo(this.videoElement);return i!=null?i:0}return t!==null&&(r=t.availabilityStartTime)!=null?r:0}getPosition(){if(this.videoElement===null)throw new Error("Disposed player");return this.videoElement.currentTime}getLastStoredContentPosition(){return this._priv_reloadingMetadata.reloadPosition}getPlaybackRate(){return this._priv_speed.getValue()}setPlaybackRate(e,t){var o;e!==this._priv_speed.getValue()&&this._priv_speed.setValue(e);let r=t==null?void 0:t.preferTrickModeTracks;if(typeof r!="boolean")return;this._priv_preferTrickModeTracks=r;let i=(o=this._priv_contentInfos)==null?void 0:o.tracksStore;E(i)||(r&&!i.isTrickModeEnabled()?i.enableVideoTrickModeTracks():!r&&i.isTrickModeEnabled()&&i.disableVideoTrickModeTracks())}getVideoRepresentation(){let e=this.__priv_getCurrentRepresentations();if(e!==null)return E(e.video)?e.video:In(e.video)}getAudioRepresentation(){let e=this.__priv_getCurrentRepresentations();if(e!==null)return E(e.audio)?e.video:Bo(e.audio)}play(){if(this.videoElement===null)throw new Error("Disposed player");let e=this.videoElement.play();return E(e)||typeof e.catch!="function"?Promise.resolve():e.catch(t=>{if(t.name==="NotAllowedError"){let r=new re("MEDIA_ERR_PLAY_NOT_ALLOWED",t.toString());this.trigger("warning",r)}throw t})}pause(){if(this.videoElement===null)throw new Error("Disposed player");this.videoElement.pause()}seekTo(e){var o;if(this.videoElement===null)throw new Error("Disposed player");if(this._priv_contentInfos===null)throw new Error("player: no content loaded");let{isDirectFile:t,manifest:r}=this._priv_contentInfos,i;if(typeof e=="number")i=e;else if(typeof e=="object"){let a=e,s=this.videoElement.currentTime;if(!E(a.relative))i=s+a.relative;else if(!E(a.position))i=a.position;else{if(E(a.wallClockTime))throw new Error('invalid time object. You must set one of the following properties: "relative", "position" or "wallClockTime"');if(r!==null)i=a.wallClockTime-((o=r.availabilityStartTime)!=null?o:0);else if(t){if(this.videoElement!==null){let d=yo(this.videoElement);d!==void 0&&(i=a.wallClockTime-d)}}else throw new Error("Cannot seek: wallClockTime asked but Manifest not yet loaded.");i===void 0&&(i=a.wallClockTime)}}if(i===void 0)throw new Error("invalid time given");return m.info("API","API seekTo",{positionWanted:i}),this._priv_contentInfos.playbackObserver.setCurrentTime(i,!1),i}getVolume(){if(this.videoElement===null)throw new Error("Disposed player");return this.videoElement.volume}setVolume(e){if(this.videoElement===null)throw new Error("Disposed player");let t=this.videoElement;e!==t.volume&&(t.volume=e)}isMute(){var e;return((e=this.videoElement)==null?void 0:e.muted)===!0}mute(){if(this.videoElement===null)throw new Error("Disposed player");this.videoElement.muted||(this.videoElement.muted=!0)}unMute(){if(this.videoElement===null)throw new Error("Disposed player");this.videoElement.muted&&(this.videoElement.muted=!1)}setMaxBufferBehind(e){this._priv_bufferOptions.maxBufferBehind.setValue(e)}setMaxBufferAhead(e){this._priv_bufferOptions.maxBufferAhead.setValue(e)}setWantedBufferAhead(e){this._priv_bufferOptions.wantedBufferAhead.setValue(e)}setMaxVideoBufferSize(e){this._priv_bufferOptions.maxVideoBufferSize.setValue(e)}getMaxBufferBehind(){return this._priv_bufferOptions.maxBufferBehind.getValue()}getMaxBufferAhead(){return this._priv_bufferOptions.maxBufferAhead.getValue()}getWantedBufferAhead(){return this._priv_bufferOptions.wantedBufferAhead.getValue()}getMaxVideoBufferSize(){return this._priv_bufferOptions.maxVideoBufferSize.getValue()}getCurrentPeriod(){var t;let e=(t=this._priv_contentInfos)==null?void 0:t.currentPeriod;return E(e)?null:{id:e.id,start:e.start,end:e.end}}getKeySystemConfiguration(){if(this.videoElement===null)throw new Error("Disposed player");let e=Zn(this.videoElement);return e===null?null:{keySystem:e[0],configuration:e[1]}}getAvailablePeriods(){if(this._priv_contentInfos===null)return[];let{isDirectFile:e,tracksStore:t}=this._priv_contentInfos;return e?[]:t===null?[]:t.getAvailablePeriods().slice()}getAvailableAudioTracks(e){var a,s;if(this._priv_contentInfos===null)return[];let{isDirectFile:t,mediaElementTracksStore:r}=this._priv_contentInfos;if(t)return(a=r==null?void 0:r.getAvailableAudioTracks())!=null?a:[];let i,o=!0;return typeof e=="string"?i=e:(i=e==null?void 0:e.periodId,o=(s=e==null?void 0:e.filterPlayableRepresentations)!=null?s:!0),this._priv_callTracksStoreGetterSetter(i,[],(d,u)=>{var c;return(c=d.getAvailableAudioTracks(u,o))!=null?c:[]})}getAvailableTextTracks(e){var i;if(this._priv_contentInfos===null)return[];let{isDirectFile:t,mediaElementTracksStore:r}=this._priv_contentInfos;return t?(i=r==null?void 0:r.getAvailableTextTracks())!=null?i:[]:this._priv_callTracksStoreGetterSetter(e,[],(o,a)=>{var s;return(s=o.getAvailableTextTracks(a))!=null?s:[]})}getAvailableVideoTracks(e){var a,s;if(this._priv_contentInfos===null)return[];let{isDirectFile:t,mediaElementTracksStore:r}=this._priv_contentInfos;if(t)return(a=r==null?void 0:r.getAvailableVideoTracks())!=null?a:[];let i,o=!0;return typeof e=="string"?i=e:(i=e==null?void 0:e.periodId,o=(s=e==null?void 0:e.filterPlayableRepresentations)!=null?s:!0),this._priv_callTracksStoreGetterSetter(i,[],(d,u)=>{var c;return(c=d.getAvailableVideoTracks(u,o))!=null?c:[]})}getAudioTrack(e){var a;if(this._priv_contentInfos===null)return;let{isDirectFile:t,mediaElementTracksStore:r}=this._priv_contentInfos;if(t)return r===null?void 0:r.getChosenAudioTrack();let i,o=!0;return typeof e=="string"?i=e:(i=e==null?void 0:e.periodId,o=(a=e==null?void 0:e.filterPlayableRepresentations)!=null?a:!0),this._priv_callTracksStoreGetterSetter(i,void 0,(s,d)=>s.getChosenAudioTrack(d,o))}getTextTrack(e){if(this._priv_contentInfos===null)return;let{isDirectFile:t,mediaElementTracksStore:r}=this._priv_contentInfos;return t?r===null?void 0:r.getChosenTextTrack():this._priv_callTracksStoreGetterSetter(e,void 0,(i,o)=>i.getChosenTextTrack(o))}getVideoTrack(e){var a;if(this._priv_contentInfos===null)return;let{isDirectFile:t,mediaElementTracksStore:r}=this._priv_contentInfos;if(t)return r===null?void 0:r.getChosenVideoTrack();let i,o=!0;return typeof e=="string"?i=e:(i=e==null?void 0:e.periodId,o=(a=e==null?void 0:e.filterPlayableRepresentations)!=null?a:!0),this._priv_callTracksStoreGetterSetter(i,void 0,(s,d)=>s.getChosenVideoTrack(d,o))}setAudioTrack(e){var u;if(this._priv_contentInfos===null)throw new Error("No content loaded");let{isDirectFile:t,mediaElementTracksStore:r}=this._priv_contentInfos;if(t)try{let c=typeof e=="string"?e:e.trackId;r==null||r.setAudioTrackById(c);return}catch(c){throw new Error("player: unknown audio track")}let i,o,a,s=null,d;return typeof e=="string"?o=e:(o=e.trackId,i=e.periodId,a=e.switchingMode,s=(u=e.lockedRepresentations)!=null?u:null,d=e.relativeResumingPosition),this._priv_callTracksStoreGetterSetter(i,void 0,(c,l)=>c.setAudioTrack({periodRef:l,trackId:o,switchingMode:a,lockedRepresentations:s,relativeResumingPosition:d}))}setTextTrack(e){if(this._priv_contentInfos===null)throw new Error("No content loaded");let{isDirectFile:t,mediaElementTracksStore:r}=this._priv_contentInfos;if(t)try{let a=typeof e=="string"?e:e.trackId;r==null||r.setTextTrackById(a);return}catch(a){throw new Error("player: unknown text track")}let i,o;return typeof e=="string"?o=e:(o=e.trackId,i=e.periodId),this._priv_callTracksStoreGetterSetter(i,void 0,(a,s)=>a.setTextTrack(s,o))}disableTextTrack(e){if(this._priv_contentInfos===null)return;let{isDirectFile:t,mediaElementTracksStore:r}=this._priv_contentInfos;if(t){r==null||r.disableTextTrack();return}return this._priv_callTracksStoreGetterSetter(e,void 0,(i,o)=>i.disableTrack(o,"text"))}setVideoTrack(e){var u;if(this._priv_contentInfos===null)throw new Error("No content loaded");let{isDirectFile:t,mediaElementTracksStore:r}=this._priv_contentInfos;if(t)try{let c=typeof e=="string"?e:e.trackId;r==null||r.setVideoTrackById(c);return}catch(c){throw new Error("player: unknown video track")}let i,o,a,s=null,d;return typeof e=="string"?o=e:(o=e.trackId,i=e.periodId,a=e.switchingMode,s=(u=e.lockedRepresentations)!=null?u:null,d=e.relativeResumingPosition),this._priv_callTracksStoreGetterSetter(i,void 0,(c,l)=>c.setVideoTrack({periodRef:l,trackId:o,switchingMode:a,lockedRepresentations:s,relativeResumingPosition:d}))}disableVideoTrack(e){if(this._priv_contentInfos===null)return;let{isDirectFile:t,mediaElementTracksStore:r}=this._priv_contentInfos;return t&&r!==null?r.disableVideoTrack():this._priv_callTracksStoreGetterSetter(e,void 0,(i,o)=>i.disableTrack(o,"video"))}lockVideoRepresentations(e){if(this._priv_contentInfos===null)throw new Error("No content loaded");let{isDirectFile:t}=this._priv_contentInfos;if(t)throw new Error("Cannot lock video Representations in directfile mode.");let r,i,o;return Array.isArray(e)?(r=e,i=void 0):(r=e.representations,i=e.periodId,o=e.switchingMode),this._priv_callTracksStoreGetterSetter(i,void 0,(a,s)=>a.lockVideoRepresentations(s,{representations:r,switchingMode:o}))}disableAudioTrack(e){if(this._priv_contentInfos===null)return;let{isDirectFile:t,mediaElementTracksStore:r}=this._priv_contentInfos;return t&&r!==null?r.disableAudioTrack():this._priv_callTracksStoreGetterSetter(e,void 0,(i,o)=>i.disableTrack(o,"audio"))}lockAudioRepresentations(e){if(this._priv_contentInfos===null)throw new Error("No content loaded");let{isDirectFile:t}=this._priv_contentInfos;if(t)throw new Error("Cannot lock audio Representations in directfile mode.");let r,i,o;return Array.isArray(e)?(r=e,i=void 0):(r=e.representations,i=e.periodId,o=e.switchingMode),this._priv_callTracksStoreGetterSetter(i,void 0,(a,s)=>a.lockAudioRepresentations(s,{representations:r,switchingMode:o}))}getLockedVideoRepresentations(e){if(this._priv_contentInfos===null)return null;let{isDirectFile:t}=this._priv_contentInfos;return t?null:this._priv_callTracksStoreGetterSetter(e,null,(r,i)=>r.getLockedVideoRepresentations(i))}getLockedAudioRepresentations(e){if(this._priv_contentInfos===null)return null;let{isDirectFile:t}=this._priv_contentInfos;return t?null:this._priv_callTracksStoreGetterSetter(e,null,(r,i)=>r.getLockedAudioRepresentations(i))}unlockVideoRepresentations(e){if(this._priv_contentInfos===null)return;let{isDirectFile:t}=this._priv_contentInfos;if(!t)return this._priv_callTracksStoreGetterSetter(e,void 0,(r,i)=>r.unlockVideoRepresentations(i))}unlockAudioRepresentations(e){if(this._priv_contentInfos===null)return;let{isDirectFile:t}=this._priv_contentInfos;if(!t)return this._priv_callTracksStoreGetterSetter(e,void 0,(r,i)=>r.unlockAudioRepresentations(i))}getMinimumPosition(){if(this._priv_contentInfos===null)return null;if(this._priv_contentInfos.isDirectFile)return 0;let{manifest:e}=this._priv_contentInfos;return e!==null?bn(e):null}getLivePosition(){if(this._priv_contentInfos===null)return null;let{isDirectFile:e,manifest:t}=this._priv_contentInfos;if(!e)return(t==null?void 0:t.isLive)!==!0?null:Sn(t)}getMaximumPosition(){if(this._priv_contentInfos===null)return null;let{isDirectFile:e,manifest:t}=this._priv_contentInfos;if(e){if(this.videoElement===null)throw new Error("Disposed player");return this.videoElement.duration}return t!==null?!t.isDynamic&&this.videoElement!==null?this.videoElement.duration:kt(t):null}async __priv_getSegmentSinkMetrics(){var e,t;return(t=(e=this._priv_contentInfos)==null?void 0:e.segmentSinkMetricsCallback)==null?void 0:t.call(e)}__priv_getManifest(){return this._priv_contentInfos===null?null:this._priv_contentInfos.manifest}__priv_getCurrentAdaptation(){if(this._priv_contentInfos===null)return null;let{currentPeriod:e,activeAdaptations:t}=this._priv_contentInfos;return e===null||t===null||E(t[e.id])?null:t[e.id]}__priv_getCurrentRepresentations(){if(this._priv_contentInfos===null)return null;let{currentPeriod:e,activeRepresentations:t}=this._priv_contentInfos;return e===null||t===null||E(t[e.id])?null:t[e.id]}_priv_cleanUpCurrentContentState(){var t,r,i,o;m.debug("API","Locking `contentLock` to clean-up the current content."),this._priv_contentLock.setValue(!0),(r=(t=this._priv_contentInfos)==null?void 0:t.tracksStore)==null||r.dispose(),(o=(i=this._priv_contentInfos)==null?void 0:i.mediaElementTracksStore)==null||o.dispose(),this._priv_contentInfos=null,this._priv_contentEventsMemory={};let e=()=>{this.videoElement!==null&&(m.debug("API","Unlocking `contentLock`. Next content can begin."),this._priv_contentLock.setValue(!1))};E(this.videoElement)?e():zo(this.videoElement).then(()=>{m.debug("API","DRM session cleaned-up with success!"),e()},a=>{m.error("API","An error arised when trying to clean-up the DRM session:"+(a instanceof Error?a.toString():"Unknown Error")),e()})}_priv_onManifestReady(e,t){var i;if(e.contentId!==((i=this._priv_contentInfos)==null?void 0:i.contentId))return;e.manifest=t,t.manifestFormat===0&&(this._priv_reloadingMetadata.manifest=t);let r=new Pp({preferTrickModeTracks:this._priv_preferTrickModeTracks,defaultAudioTrackSwitchingMode:e.defaultAudioTrackSwitchingMode,onTracksNotPlayableForType:{audio:e.onAudioTracksNotPlayable,video:e.onVideoTracksNotPlayable,text:"continue"}});e.tracksStore=r,r.addEventListener("newAvailablePeriods",o=>{this.trigger("newAvailablePeriods",o)}),r.addEventListener("brokenRepresentationsLock",o=>{this.trigger("brokenRepresentationsLock",o)}),r.addEventListener("trackUpdate",o=>{var s,d;this.trigger("trackUpdate",o);let a=(d=(s=this._priv_contentInfos)==null?void 0:s.currentPeriod)!=null?d:void 0;o.reason==="no-playable-representation"&&o.period.id===(a==null?void 0:a.id)&&this._priv_onAvailableTracksMayHaveChanged(o.trackType)}),r.addEventListener("warning",o=>{this.trigger("warning",o)}),r.addEventListener("error",o=>{this._priv_onFatalError(o,e)}),r.addEventListener("noPlayableTrack",o=>{this.trigger("noPlayableTrack",o)}),r.onManifestUpdate(t)}_priv_onManifestUpdate(e,t){var o,a,s;if(this._priv_contentInfos===null||this._priv_contentInfos.manifest===null)return;E(e==null?void 0:e.tracksStore)||e.tracksStore.onManifestUpdate(this._priv_contentInfos.manifest);let r=(a=(o=this._priv_contentInfos)==null?void 0:o.currentPeriod)!=null?a:void 0,i=(s=this._priv_contentInfos)==null?void 0:s.tracksStore;if(!(r===void 0||E(i))){for(let d of t.updatedPeriods)if(d.period.id===r.id&&(d.result.addedAdaptations.length>0||d.result.removedAdaptations.length>0)){if(i.getPeriodObjectFromPeriod(r)===void 0)return;this._priv_onAvailableTracksMayHaveChanged("audio"),this._priv_onAvailableTracksMayHaveChanged("text"),this._priv_onAvailableTracksMayHaveChanged("video")}}}_priv_onCodecSupportUpdate(e){let t=e==null?void 0:e.tracksStore;E(t)||t.onManifestCodecSupportUpdate()}_priv_onDecipherabilityUpdate(e,t){if(e===null||e.manifest===null)return;E(e==null?void 0:e.tracksStore)||e.tracksStore.onDecipherabilityUpdates();let r=t.reduce((i,o)=>{var s,d,u;if(!(Q(i,c=>c[0].id===o.period.id&&c[1]===o.adaptation.type)!==void 0)){let c=e.tracksStore;if(c===null)return i;let l=!1,f=c.getPeriodObjectFromPeriod(o.period);if(f===void 0)return i;switch(o.adaptation.type){case"audio":l=((s=c.getChosenAudioTrack(f,!1))==null?void 0:s.id)===o.adaptation.id;break;case"video":l=((d=c.getChosenVideoTrack(f,!1))==null?void 0:d.id)===o.adaptation.id;break;case"text":l=((u=c.getChosenTextTrack(f))==null?void 0:u.id)===o.adaptation.id;break}l&&i.push([o.period,o.adaptation.type])}return i},[]);for(let[i,o]of r)this._priv_triggerEventIfNotStopped("representationListUpdate",{period:{start:i.start,end:i.end,id:i.id},trackType:o,reason:"decipherability-update"},e.currentContentCanceller.signal)}_priv_onActivePeriodChanged(e,{period:t}){var s,d,u,c,l,f;if(e.contentId!==((s=this._priv_contentInfos)==null?void 0:s.contentId))return;e.currentPeriod=t;let r=e.currentContentCanceller.signal;this._priv_contentEventsMemory.periodChange!==t&&(this._priv_contentEventsMemory.periodChange=t,this._priv_triggerEventIfNotStopped("periodChange",{start:t.start,end:t.end,id:t.id},r)),this._priv_triggerEventIfNotStopped("availableAudioTracksChange",this.getAvailableAudioTracks(),r),this._priv_triggerEventIfNotStopped("availableTextTracksChange",this.getAvailableTextTracks(),r),this._priv_triggerEventIfNotStopped("availableVideoTracksChange",this.getAvailableVideoTracks(),r);let i=(d=this._priv_contentInfos)==null?void 0:d.tracksStore;if(E(i))this._priv_triggerEventIfNotStopped("audioTrackChange",null,r),this._priv_triggerEventIfNotStopped("textTrackChange",null,r),this._priv_triggerEventIfNotStopped("videoTrackChange",null,r);else{let p=i.getPeriodObjectFromPeriod(t);if(p!==void 0){let h=i.getChosenAudioTrack(p,!0);this._priv_triggerEventIfNotStopped("audioTrackChange",h,r);let I=i.getChosenTextTrack(p);this._priv_triggerEventIfNotStopped("textTrackChange",I,r);let g=i.getChosenVideoTrack(p,!0);this._priv_triggerEventIfNotStopped("videoTrackChange",g,r)}}let o=(c=(u=this.__priv_getCurrentRepresentations())==null?void 0:u.audio)!=null?c:null;this._priv_triggerEventIfNotStopped("audioRepresentationChange",E(o)?o:In(o),r);let a=(f=(l=this.__priv_getCurrentRepresentations())==null?void 0:l.video)!=null?f:null;this._priv_triggerEventIfNotStopped("videoRepresentationChange",E(a)?a:In(a),r)}_priv_onPeriodStreamReady(e,t){var s;if(e.contentId!==((s=this._priv_contentInfos)==null?void 0:s.contentId))return;let{type:r,period:i,adaptationRef:o}=t,a=e.tracksStore;switch(r){case"video":case"audio":case"text":E(a)?(m.error("API",`TracksStore not instanciated for a new ${r} period`),o.setValue(null)):a.addTrackReference(r,i,o);break;default:ze(r)}}_priv_onPeriodStreamCleared(e,t){var d;if(e.contentId!==((d=this._priv_contentInfos)==null?void 0:d.contentId))return;let{type:r,periodId:i}=t,o=e.tracksStore;switch(r){case"audio":case"text":case"video":E(o)||o.removeTrackReference(r,i);break}let{activeAdaptations:a,activeRepresentations:s}=e;if(!E(a)&&!E(a[i])){let u=a[i];delete u[r],Object.keys(u).length===0&&delete a[i]}if(!E(s)&&!E(s[i])){let u=s[i];delete u[r],Object.keys(u).length===0&&delete s[i]}}_priv_onAdaptationChange(e,{type:t,adaptation:r,period:i}){var c;if(e.contentId!==((c=this._priv_contentInfos)==null?void 0:c.contentId))return;e.activeAdaptations===null&&(e.activeAdaptations={});let{activeAdaptations:o,currentPeriod:a}=e,s=o[i.id];E(s)?o[i.id]={[t]:r}:s[t]=r;let{tracksStore:d}=e,u=e.currentContentCanceller.signal;if(d!==null&&a!==null&&!E(i)&&i.id===a.id){let l=d.getPeriodObjectFromPeriod(i);if(l===void 0)return;switch(t){case"audio":{let f=d.getChosenAudioTrack(l,!0);this._priv_triggerEventIfNotStopped("audioTrackChange",f,u);break}case"text":{let f=d.getChosenTextTrack(l);this._priv_triggerEventIfNotStopped("textTrackChange",f,u);break}case"video":{let f=d.getChosenVideoTrack(l,!0);this._priv_triggerEventIfNotStopped("videoTrackChange",f,u);break}}}}_priv_onRepresentationChange(e,{type:t,period:r,representation:i}){var d;if(e.contentId!==((d=this._priv_contentInfos)==null?void 0:d.contentId))return;e.activeRepresentations===null&&(e.activeRepresentations={});let{activeRepresentations:o,currentPeriod:a}=e,s=o[r.id];if(E(s)?o[r.id]={[t]:i}:s[t]=i,!E(r)&&a!==null&&a.id===r.id){let u=this._priv_contentInfos.currentContentCanceller.signal;t==="video"?this._priv_triggerEventIfNotStopped("videoRepresentationChange",E(i)?i:In(i),u):t==="audio"&&this._priv_triggerEventIfNotStopped("audioRepresentationChange",E(i)?i:Bo(i),u)}}_priv_onBitrateEstimateChange({type:e,bitrate:t}){t!==void 0&&(this._priv_bitrateInfos.lastBitrates[e]=t),this.trigger("__priv_bitrateEstimateChange",{type:e,bitrate:t})}_priv_setPlayerState(e){this.state!==e&&(this.state=e,m.info("API","playerStateChange event",{newState:e}),this.trigger("playerStateChange",e))}_priv_triggerPositionUpdate(e,t){var s,d;if(e.contentId!==((s=this._priv_contentInfos)==null?void 0:s.contentId))return;let{isDirectFile:r,manifest:i}=e;if(!r&&i===null||E(t))return;let o=i!==null?kt(i):void 0,a={position:t.position.getPolled(),duration:t.duration,playbackRate:t.playbackRate,maximumPosition:o,bufferGap:t.bufferGap===void 0||!isFinite(t.bufferGap)?0:t.bufferGap};if(i!==null&&i.isLive&&t.position.getPolled()>0){let u=(d=i.availabilityStartTime)!=null?d:0;a.wallClockTime=t.position.getPolled()+u;let c=Sn(i);c!==void 0&&(a.liveGap=c-t.position.getPolled())}else if(r&&this.videoElement!==null){let u=yo(this.videoElement);u!==void 0&&(a.wallClockTime=u+t.position.getPolled())}this.trigger("positionUpdate",a)}_priv_triggerEventIfNotStopped(e,t,r){r.isCancelled()||this.trigger(e,t)}_priv_initializeMediaElementTracksStore(e){var r,i,o;ne(pe.directfile!==null,"Initializing `MediaElementTracksStore` without Directfile feature"),ne(this.videoElement!==null,"Initializing `MediaElementTracksStore` on a disposed RxPlayer");let t=new pe.directfile.mediaElementTracksStore(this.videoElement);return this._priv_triggerEventIfNotStopped("availableAudioTracksChange",t.getAvailableAudioTracks(),e),this._priv_triggerEventIfNotStopped("availableVideoTracksChange",t.getAvailableVideoTracks(),e),this._priv_triggerEventIfNotStopped("availableTextTracksChange",t.getAvailableTextTracks(),e),this._priv_triggerEventIfNotStopped("audioTrackChange",(r=t.getChosenAudioTrack())!=null?r:null,e),this._priv_triggerEventIfNotStopped("textTrackChange",(i=t.getChosenTextTrack())!=null?i:null,e),this._priv_triggerEventIfNotStopped("videoTrackChange",(o=t.getChosenVideoTrack())!=null?o:null,e),t.addEventListener("availableVideoTracksChange",a=>this.trigger("availableVideoTracksChange",a)),t.addEventListener("availableAudioTracksChange",a=>this.trigger("availableAudioTracksChange",a)),t.addEventListener("availableTextTracksChange",a=>this.trigger("availableTextTracksChange",a)),t.addEventListener("audioTrackChange",a=>this.trigger("audioTrackChange",a)),t.addEventListener("videoTrackChange",a=>this.trigger("videoTrackChange",a)),t.addEventListener("textTrackChange",a=>this.trigger("textTrackChange",a)),t}_priv_callTracksStoreGetterSetter(e,t,r){var d,u;if(this._priv_contentInfos===null||this._priv_contentInfos.tracksStore===null)return m.warn("API","Trying to call track API too soon"),t;let{tracksStore:i}=this._priv_contentInfos,o=(u=(d=this._priv_contentInfos)==null?void 0:d.currentPeriod)!=null?u:void 0,a=e!=null?e:o==null?void 0:o.id;if(a===void 0)return t;let s=a===(o==null?void 0:o.id)?i.getPeriodObjectFromPeriod(o):i.getPeriodObjectFromId(a);return s===void 0?t:r(i,s)}_priv_onAvailableTracksMayHaveChanged(e,t){let r=this._priv_contentInfos;if(r===null)return;let{currentPeriod:i,tracksStore:o,currentContentCanceller:a}=r,s=a.signal;if(E(i)||o===null)return;let d=t!=null?t:o.getPeriodObjectFromPeriod(i);if(d!==void 0)switch(e){case"video":{let u=o.getAvailableVideoTracks(d,!0);this._priv_triggerEventIfNotStopped("availableVideoTracksChange",u!=null?u:[],s);break}case"audio":{let u=o.getAvailableAudioTracks(d,!0);this._priv_triggerEventIfNotStopped("availableAudioTracksChange",u!=null?u:[],s);break}case"text":{let u=o.getAvailableTextTracks(d);this._priv_triggerEventIfNotStopped("availableTextTracksChange",u!=null?u:[],s);break}default:ze(e)}}_priv_onFatalError(e,t){let r=Me(e,{defaultCode:"NONE",defaultReason:"An unknown error stopped content playback."});r.fatal=!0,t.currentContentCanceller.cancel(),this._priv_cleanUpCurrentContentState(),this._priv_currentError=r,m.error("API","The player stopped because of an error",r),this._priv_setPlayerState("STOPPED"),this._priv_currentError===r&&this.trigger("error",r)}};Yt._priv_currentlyUsedVideoElements=new WeakSet;var Ir=Yt;Ir.version="4.4.0-dev.2025092404";var Dp=Ir;var es=Dp;ts();es.addFeatures([Fl,Au,Du,Lu,Cl,_l,Ml,Rl,ll,Ku,bl,Wu]);var nue=es;Z.RxPlayer=es;})();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "rx-player",
3
3
  "author": "Canal+",
4
- "version": "4.4.0-dev.2025092200",
4
+ "version": "4.4.0-dev.2025092404",
5
5
  "description": "Canal+ HTML5 Video Player",
6
6
  "main": "./dist/commonjs/index.js",
7
7
  "module": "./dist/es2017/index.js",
@@ -445,7 +445,7 @@ class Player extends EventEmitter<IPublicAPIEvent> {
445
445
  // See: https://bugzilla.mozilla.org/show_bug.cgi?id=1194624
446
446
  videoElement.preload = "auto";
447
447
 
448
- this.version = /* PLAYER_VERSION */ "4.4.0-dev.2025092200";
448
+ this.version = /* PLAYER_VERSION */ "4.4.0-dev.2025092404";
449
449
  this.log = log;
450
450
  this.state = "STOPPED";
451
451
  this.videoElement = videoElement;
@@ -3576,7 +3576,7 @@ class Player extends EventEmitter<IPublicAPIEvent> {
3576
3576
  }
3577
3577
  }
3578
3578
  }
3579
- Player.version = /* PLAYER_VERSION */ "4.4.0-dev.2025092200";
3579
+ Player.version = /* PLAYER_VERSION */ "4.4.0-dev.2025092404";
3580
3580
 
3581
3581
  /** Every events sent by the RxPlayer's public API. */
3582
3582
  interface IPublicAPIEvent {