define(["events","datetime","appSettings","pluginManager","userSettings","globalize","connectionManager","loading","serverNotifications","apphost","fullscreenManager","layoutManager"],function(events,datetime,appSettings,pluginManager,userSettings,globalize,connectionManager,loading,serverNotifications,apphost,fullscreenManager,layoutManager){"use strict";functionenableLocalPlaylistManagement(player){return!!player.isLocalPlayer}functionbindToFullscreenChange(player){events.on(fullscreenManager,"fullscreenchange",function(){events.trigger(player,"fullscreenchange")})}functiontriggerPlayerChange(playbackManagerInstance,newPlayer,newTarget,previousPlayer,previousTargetInfo){(newPlayer||previousPlayer)&&(newTarget&&previousTargetInfo&&newTarget.id===previousTargetInfo.id||events.trigger(playbackManagerInstance,"playerchange",[newPlayer,newTarget,previousPlayer]))}functionreportPlayback(state,serverId,method,progressEventName){if(serverId){varinfo=Object.assign({},state.PlayState);info.ItemId=state.NowPlayingItem.Id,progressEventName&&(info.EventName=progressEventName);varapiClient=connectionManager.getApiClient(serverId);apiClient[method](info)}}functionPlaybackManager(){functiondisplayPlayerInLocalGroup(player){returnplayer.isLocalPlayer}functiongetSupportedCommands(player){if(player.isLocalPlayer){varlist=["GoHome","GoToSettings","VolumeUp","VolumeDown","Mute","Unmute","ToggleMute","SetVolume","SetAudioStreamIndex","SetSubtitleStreamIndex","SetMaxStreamingBitrate","DisplayContent","GoToSearch","DisplayMessage","SetRepeatMode"];returnapphost.supports("fullscreenchange")&&!layoutManager.tv&&list.push("ToggleFullscreen"),player.supports&&(player.supports("PictureInPicture")&&list.push("PictureInPicture"),player.supports("SetBrightness")&&list.push("SetBrightness"),player.supports("SetAspectRatio")&&list.push("SetAspectRatio")),list}thrownewError("player must define supported commands")}functioncreateTarget(player){return{name:player.name,id:player.id,playerName:player.name,playableMediaTypes:["Audio","Video","Game"].map(player.canPlayMediaType),isLocalPlayer:player.isLocalPlayer,supportedCommands:getSupportedCommands(player)}}functiongetPlayerTargets(player){returnplayer.getTargets?player.getTargets():Promise.resolve([createTarget(player)])}functiongetCurrentSubtitleStream(player){if(!player)thrownewError("player cannot be null");varindex=getPlayerData(player).subtitleStreamIndex;returnnull==index||index===-1?null:getSubtitleStream(player,index)}functiongetSubtitleStream(player,index){returnself.currentMediaSource(player).MediaStreams.filter(function(s){return"Subtitle"===s.Type&&s.Index===index})[0]}functionsetCurrentPlayerInternal(player,targetInfo){varpreviousPlayer=currentPlayer,previousTargetInfo=currentTargetInfo;if(player&&!targetInfo&&player.isLocalPlayer&&(targetInfo=createTarget(player)),player&&!targetInfo)thrownewError("targetInfo cannot be null");currentPairingId=null,currentPlayer=player,currentTargetInfo=targetInfo,targetInfo&&console.log("Active player: "+JSON.stringify(targetInfo)),player&&player.isLocalPlayer&&(lastLocalPlayer=player),previousPlayer&&self.endPlayerUpdates(previousPlayer),player&&self.beginPlayerUpdates(player),triggerPlayerChange(self,player,targetInfo,previousPlayer,previousTargetInfo)}functiongetAutomaticPlayers(){varplayer=currentPlayer;returnplayer&&!enableLocalPlaylistManagement(player)?[player]:self.getPlayers().filter(enableLocalPlaylistManagement)}functioncanPlayerSeek(player){if(!player)thrownewError("player cannot be null");varplayerData=getPlayerData(player),currentSrc=(playerData.streamInfo.url||"").toLowerCase();returncurrentSrc.indexOf(".m3u8")!==-1||"Transcode"!==playerData.streamInfo.playMethod&&player.duration()}functionchangeStream(player,ticks,params){if(canPlayerSeek(player)&&null==params)returnvoidplayer.currentTime(parseInt(ticks/1e4));params=params||{};varliveStreamId=getPlayerData(player).streamInfo.liveStreamId,playSessionId=getPlayerData(player).streamInfo.playSessionId,playerData=getPlayerData(player),currentItem=playerData