events.trigger(self,"playbackstop",[playbackStopInfo]);varnewPlayer=nextItem?getPlayer(nextItem.item,currentPlayOptions):null;newPlayer!==player&&(destroyPlayer(player),removeCurrentPlayer(player))})}functionacquireResourceLocks(player,mediaType){if(!player)thrownewError("player cannot be null");if(player.isLocalPlayer&&!player.hasResourceLocks){varplayerData=getPlayerData(player);playerData.resourceLocks=playerData.resourceLocks||{};varlocks=playerData.resourceLocks;ensureLock(locks,"network"),ensureLock(locks,"wake"),"Video"===mediaType&&ensureLock(locks,"screen")}}functionensureLock(locks,resourceType){varprop=resourceType+"Lock",existingLock=locks[prop];returnexistingLock?voidexistingLock.acquire():voidrequire(["resourceLockManager"],function(resourceLockManager){resourceLockManager.request(resourceType).then(function(resourceLock){locks[prop]=resourceLock,resourceLock.acquire()},function(){})})}functionreleaseResourceLocks(player){if(!player)thrownewError("player cannot be null");if(player.isLocalPlayer&&!player.hasResourceLocks){varplayerData=getPlayerData(player),locks=playerData.resourceLocks||{};locks.wakeLock&&locks.wakeLock.release(),locks.networkLock&&locks.networkLock.release(),locks.screenLock&&locks.screenLock.release()}}functionenablePlaybackRetryWithTranscoding(streamInfo,errorType){return!!streamInfo&&(!("mediadecodeerror"!==errorType&&"medianotsupported"!==errorType||"Transcode"===streamInfo.playMethod||!streamInfo.mediaSource.SupportsTranscoding)||!("network"!==errorType||"DirectPlay"!==streamInfo.playMethod||!streamInfo.mediaSource.IsRemote||!streamInfo.mediaSource.SupportsTranscoding))}functiononPlaybackError(e,error){varplayer=this;error=error||{};varerrorType=error.type;console.log("playbackmanager playback error type: "+(errorType||""));varstreamInfo=getPlayerData(player).streamInfo;if(enablePlaybackRetryWithTranscoding(streamInfo,errorType)){varstartTime=getCurrentTicks(player)||streamInfo.playerStartPositionTicks;returnvoidchangeStream(player,startTime,{EnableDirectPlay:!1,EnableDirectStream:!1,AllowVideoStreamCopy:!1,AllowAudioStreamCopy:!1},!0)}onPlaybackStopped.call(player,e)}functiononPlaybackStopped(e){varplayer=this;getPlayerData(player).isChangingStream||self.getPlayerState(player).then(function(state){varstreamInfo=getPlayerData(player).streamInfo,nextItem=self._playNextAfterEnded?self._playQueueManager.getNextItemInfo():null,nextMediaType=nextItem?nextItem.item.MediaType:null,playbackStopInfo={player:player,state:state,nextItem:nextItem?nextItem.item:null,nextMediaType:nextMediaType};state.NextMediaType=nextMediaType,isServerItem(streamInfo.item)&&(player.supportsProgress===!1&&state.PlayState&&!state.PlayState.PositionTicks&&(state.PlayState.PositionTicks=streamInfo.item.RunTimeTicks),streamInfo.ended=!0,reportPlayback(state,streamInfo.item.ServerId,"reportPlaybackStopped")),state.NextItem=playbackStopInfo.nextItem,nextItem||self._playQueueManager.reset(),events.trigger(player,"playbackstop",[state]),events.trigger(self,"playbackstop",[playbackStopInfo]);varnewPlayer=nextItem?getPlayer(nextItem.item,currentPlayOptions):null;newPlayer!==player&&(destroyPlayer(player),removeCurrentPlayer(player)),nextItem&&self.nextTrack()})}functiononPlaybackChanging(activePlayer,newPlayer,newItem){returnself.getPlayerState(activePlayer).then(function(state){varpromise,serverId=self.currentItem(activePlayer).ServerId;returnunbindStopped(activePlayer),promise=activePlayer===newPlayer?activePlayer.stop(!1):activePlayer.stop(!0),promise.then(function(){bindStopped(activePlayer),enableLocalPlaylistManagement(activePlayer)&&reportPlayback(state,serverId,"reportPlaybackStopped"),events.trigger(self,"playbackstop",[{player:activePlayer,state:state,nextItem:newItem,nextMediaType:newItem.MediaType}])})})}functionbindStopped(player){enableLocalPlaylistManagement(player)&&(events.off(player,"stopped",onPlaybackStopped),events.on(player,"stopped",onPlaybackStopped))}functiononPlaybackTimeUpdate(e){varplayer=this;sendProgressUpdate(player,"timeupdate")}functiononPlaybackPause(e){
varplayerInfo=this.getPlayerInfo();playerInfo&&playerInfo.name===name&&this.setDefaultPlayerActive()},PlaybackManager.prototype.removeActiveTarget=function(id){varplayerInfo=this.getPlayerInfo();playerInfo&&playerInfo.id===id&&this.setDefaultPlayerActive()},PlaybackManager.prototype.sendCommand=function(cmd,player){switch(console.log("MediaController received command: "+cmd.Name),cmd.Name){case"SetRepeatMode":this.setRepeatMode(cmd.Arguments.RepeatMode,player);break;case"VolumeUp":this.volumeUp(player);break;case"VolumeDown":this.volumeDown(player);break;case"Mute":this.setMute(!0,player);break;case"Unmute":this.setMute(!1,player);break;case"ToggleMute":this.toggleMute(player);break;case"SetVolume":this.setVolume(cmd.Arguments.Volume,player);break;case"SetAspectRatio":this.setAspectRatio(cmd.Arguments.AspectRatio,player);break;case"SetBrightness":this.setBrightness(cmd.Arguments.Brightness,player);break;case"SetAudioStreamIndex":this.setAudioStreamIndex(parseInt(cmd.Arguments.Index),player);break;case"SetSubtitleStreamIndex":this.setSubtitleStreamIndex(parseInt(cmd.Arguments.Index),player);break;case"SetMaxStreamingBitrate":break;case"ToggleFullscreen":this.toggleFullscreen(player);break;default:player.sendCommand&&player.sendCommand(cmd)}},newPlaybackManager});