define(["exports","./../emby-apiclient/connectionmanager.js","./../browser.js","./../common/appsettings.js","./../emby-apiclient/events.js"],function(_exports,_connectionmanager,_browser,_appsettings,_events){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0;var recoverDecodingErrorDate,recoverSwapAudioCodecDate,isNativeLG="webos"===globalThis.appMode;function BaseHtmlPlayer(){this.type="mediaplayer",this.boundOnVolumeChange=function(e){var _instance$_currentPla,e=e.target;this._isFadingOut||(null!=(_instance$_currentPla=this._currentPlayOptions)&&_instance$_currentPla.fullscreen&&this.useElementVolume()&&_appsettings.default.volume(100*e.volume),_events.default.trigger(this,"volumechange"))}.bind(this),this.boundOnWaiting=function(e){_events.default.trigger(this,"waiting")}.bind(this),this.boundOnRateChange=function(){_events.default.trigger(this,"playbackratechange")}.bind(this),this.boundOnPlay=function(e){_events.default.trigger(this,"unpause")}.bind(this),this.boundOnPause=function(){_events.default.trigger(this,"pause")}.bind(this),this.boundOnEnded=function(e){this.onEnded(e.target)}.bind(this),this.boundOnError=onError.bind(this),this.boundOnTimeUpdate=function(e){e=e.target;{var time;this._started&&!this._isFadingOut&&((time=e.currentTime)&&!this._timeUpdated&&(this._timeUpdated=!0,this.onTimeUpdate(e,time,!0)),this._currentTime=time,this.onTimeUpdate(e,time),_events.default.trigger(this,"timeupdate"))}}.bind(this),this.boundOnPlaying=function(e){e=e.target;this._started||(this._started=!0,this.onStartedPlaying(e));_events.default.trigger(this,"playing")}.bind(this)}function isValidDuration(duration){return!(!duration||isNaN(duration)||duration===Number.POSITIVE_INFINITY||duration===Number.NEGATIVE_INFINITY)}function getRanges(instance,elem,timeRanges){for(var ranges=[],instance=instance._currentPlayOptions,offset=(offset=instance?instance.transcodingOffsetTicks:offset)||0,i=0,length=timeRanges.length;i=allowance&&(element.currentTime=seconds)}function rejectWithError(reject,errorCode){var e=new Error("Playback failure");errorCode&&(e.name=errorCode),reject(e)}function bindEventsToHlsPlayer(instance,hls,elem,resolve,reject){hls.on(Hls.Events.MANIFEST_PARSED,function(){instance.playWithPromise(elem).then(function(result){reject=null,resolve(result)},function(){reject&&(reject(),reject=null)})}),hls.on(Hls.Events.ERROR,function(event,data){if(console.log("HLS Error: Type: "+data.type+" Details: "+(data.details||"")+" Fatal: "+(data.fatal||!1)+" Reason: "+(data.reason||"")),data.type===Hls.ErrorTypes.NETWORK_ERROR)if(data.response&&data.response.code&&400<=data.response.code)return console.log("hls.js response error code: "+data.response.code),hls.destroy(),void(reject?(rejectWithError(reject,"servererror"),reject=null):instance.onError("servererror"));if(data.fatal||reject)switch(data.type){case Hls.ErrorTypes.NETWORK_ERROR:reject||data.response&&0===data.response.code?(data.response&&console.log("hls.js response error code: "+data.response.code),hls.destroy(),reject?(rejectWithError(reject,"network"),reject=null):instance.onError("network")):(console.log("fatal network error encountered, try to recover"),hls.startLoad());break;case Hls.ErrorTypes.MEDIA_ERROR:console.log("media error encountered, try to recover");var currentReject=reject;reject=null,currentReject?rejectWithError(currentReject,"mediadecodeerror"):handleHlsJsMediaError(instance,currentReject);break;default:console.log("Cannot recover from hls error - destroy and trigger error"),hls.destroy(),reject?(rejectWithError(reject,"mediadecodeerror"),reject=null):instance.onError("mediadecodeerror")}})}function handleHlsJsMediaError(instance,reject){var now,hlsPlayer=instance._hlsPlayer;hlsPlayer&&(now=Date.now(),window.performance&&window.performance.now&&(now=performance.now()),!recoverDecodingErrorDate||3e3