define(["exports","./../emby-apiclient/connectionmanager.js","./../common/playback/playbackmanager.js","./../emby-apiclient/events.js"],function(_exports,_connectionmanager,_playbackmanager,_events){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0;_exports.default=new function(){var self=this,player=null;function onPlayerEvent(e,state){state=state||self.getPlayerState(),_events.default.trigger(self,e.type,[state])}function onTimeUpdateEvent(e,state){var _state=(null==(_state=state=state||self.getPlayerState())||null==(_state=_state.NowPlayingItem)?void 0:_state.RunTimeTicks)||0,state=(null==(state=state)?void 0:state.PositionTicks)||0;_events.default.trigger(self,e.type,[state,_state])}function bindToPlayer(newPlayer){player&&(_events.default.off(player,"playbackstart",onPlayerEvent),_events.default.off(player,"playbackstop",onPlayerEvent),_events.default.off(player,"unpause",onPlayerEvent),_events.default.off(player,"pause",onPlayerEvent),_events.default.off(player,"statechange",onPlayerEvent),_events.default.off(player,"timeupdate",onTimeUpdateEvent),_events.default.trigger(self,"uninit",[player]),player=null),newPlayer&&(player=newPlayer,_events.default.on(player,"playbackstart",onPlayerEvent),_events.default.on(player,"playbackstop",onPlayerEvent),_events.default.on(player,"unpause",onPlayerEvent),_events.default.on(player,"pause",onPlayerEvent),_events.default.on(player,"statechange",onPlayerEvent),_events.default.on(player,"timeupdate",onTimeUpdateEvent),_events.default.trigger(self,"init",[player]))}this.get=function(){return player},this.nextTrack=function(){return player?_playbackmanager.default.nextTrack(player):Promise.reject()},this.previousTrack=function(){return player?_playbackmanager.default.previousTrack(player):Promise.reject()},this.pause=function(){player&&_playbackmanager.default.pause(player)},this.unpause=function(){player&&_playbackmanager.default.unpause(player)},this.stop=function(){return player?_playbackmanager.default.stop(player):Promise.reject()},this.rewind=function(){return player?_playbackmanager.default.rewind(player):Promise.reject()},this.fastForward=function(){return player?_playbackmanager.default.fastForward(player):Promise.reject()},this.seek=function(ticks){return player?_playbackmanager.default.seek(ticks,player):Promise.reject()},this.seekable=function(){return!(!player||!player.seekable)&&player.seekable()},this.duration=function(){return player?player.duration():0},this.currentTime=function(){return player?player.currentTime():0},this.paused=function(){return!!player&&player.paused()},this.getPlayerState=function(){return player?_playbackmanager.default.getPlayerState(player):null},this.isPairing=function(){return _playbackmanager.default.isPairing()},this.getImageUrl=function(serverId,itemId,options){return _connectionmanager.default.getApiClient({ServerId:serverId}).getImageUrl(itemId,options)},_events.default.on(_playbackmanager.default,"playerchange",function(){bindToPlayer(_playbackmanager.default.getCurrentPlayer())}),bindToPlayer(_playbackmanager.default.getCurrentPlayer()),navigator.mediaSession&&(navigator.mediaSession.metadata=new MediaMetadata({title:"none",artist:"none"}),window.setTimeout(function(){return navigator.mediaSession.metadata=null},500))}});