protected static IPlayerContext PreparePlayerContext(AVType avType, bool play, PlayerContextConcurrencyMode concurrencyMode) { IPlayerContextManager pcm = ServiceRegistration.Get <IPlayerContextManager>(); string contextName; if (!GetPlayerContextNameForMediaType(avType, out contextName)) { return(null); } IPlayerContext pc = null; if (!play) { // !play means enqueue - so find our first player context of the correct media type IList <IPlayerContext> playerContexts = new List <IPlayerContext>( pcm.GetPlayerContextsByMediaModuleId(Consts.MODULE_ID_MEDIA).Where(playerContext => playerContext.AVType == avType)); // In case the media type is audio, we have max. one player context of that type. In case media type is // video, we might have two. But we handle enqueue only for the first video player context. pc = playerContexts.FirstOrDefault(); } if (pc == null) { // No player context to reuse - so open a new one if (avType == AVType.Video) { pc = pcm.OpenVideoPlayerContext(Consts.MODULE_ID_MEDIA, contextName, concurrencyMode, Consts.WF_STATE_ID_CURRENTLY_PLAYING_VIDEO, Consts.WF_STATE_ID_FULLSCREEN_VIDEO); } else if (avType == AVType.Audio) { pc = pcm.OpenAudioPlayerContext(Consts.MODULE_ID_MEDIA, contextName, concurrencyMode == PlayerContextConcurrencyMode.ConcurrentVideo, Consts.WF_STATE_ID_CURRENTLY_PLAYING_AUDIO, Consts.WF_STATE_ID_FULLSCREEN_AUDIO); } } if (pc == null) { return(null); } if (play) { pc.Playlist.Clear(); } return(pc); }
public void StartPartyMode() { ServiceRegistration.Get <ILogger>().Info("PartyMusicPlayerModel: Starting party mode"); SaveSettings(); if (!LoadPlaylist()) { return; } LoadPlayRepeatMode(); IPlayerContextManager pcm = ServiceRegistration.Get <IPlayerContextManager>(); IPlayerContext audioPlayerContext = pcm.OpenAudioPlayerContext(Consts.MODULE_ID_PARTY_MUSIC_PLAYER, Consts.RES_PLAYER_CONTEXT_NAME, false, Consts.WF_STATE_ID_PARTY_MUSIC_PLAYER, Consts.WF_STATE_ID_PARTY_MUSIC_PLAYER); IPlaylist playlist = audioPlayerContext.Playlist; playlist.StartBatchUpdate(); try { playlist.Clear(); foreach (MediaItem mediaItem in _mediaItems) { playlist.Add(mediaItem); } playlist.PlayMode = PlayMode; playlist.RepeatMode = RepeatMode; _playerContext = audioPlayerContext; } finally { playlist.EndBatchUpdate(); } audioPlayerContext.Play(); IWorkflowManager workflowManager = ServiceRegistration.Get <IWorkflowManager>(); workflowManager.NavigatePushAsync(Consts.WF_STATE_ID_PARTY_MUSIC_PLAYER); }