예제 #1
0
        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);
        }