예제 #1
0
        /// <summary>
        /// Depending on parameter <paramref name="play"/>, plays or enqueues the specified media <paramref name="item"/>.
        /// </summary>
        /// <param name="item">Media item to be played.</param>
        /// <param name="play">If <c>true</c>, plays the specified <paramref name="item"/>, else enqueues it.</param>
        /// <param name="concurrencyMode">Determines if the media item will be played or enqueued in concurrency mode.</param>
        /// <param name="resumeState">Contains optional information for players to resume playback.</param>
        public static async Task PlayOrEnqueueItem(MediaItem item, bool play, PlayerContextConcurrencyMode concurrencyMode, IResumeState resumeState = null)
        {
            IPlayerContextManager pcm = ServiceRegistration.Get <IPlayerContextManager>();
            AVType         avType     = pcm.GetTypeOfMediaItem(item);
            IPlayerContext pc         = PreparePlayerContext(avType, play, concurrencyMode);

            if (pc == null)
            {
                return;
            }

            // Always add items to playlist. This allows audio playlists as well as video/image playlists.
            pc.Playlist.Add(item);

            await CompletePlayOrEnqueue(pc, play, resumeState);
        }
예제 #2
0
        /// <summary>
        /// Depending on parameter <paramref name="play"/>, plays or enqueues the specified media <paramref name="item"/>.
        /// </summary>
        /// <param name="item">Media item to be played.</param>
        /// <param name="play">If <c>true</c>, plays the specified <paramref name="item"/>, else enqueues it.</param>
        /// <param name="concurrencyMode">Determines if the media item will be played or enqueued in concurrency mode.</param>
        public static void PlayOrEnqueueItem(MediaItem item, bool play, PlayerContextConcurrencyMode concurrencyMode)
        {
            IPlayerContextManager pcm = ServiceRegistration.Get <IPlayerContextManager>();
            AVType         avType     = pcm.GetTypeOfMediaItem(item);
            IPlayerContext pc         = PreparePlayerContext(avType, play, concurrencyMode);

            if (pc == null)
            {
                return;
            }

            // Always add items to playlist. This allows audio playlists as well as video/image playlists.
            pc.Playlist.Add(item);

            ServiceRegistration.Get <IThreadPool>().Add(() => CompletePlayOrEnqueue(pc, play));
        }
예제 #3
0
        protected void CheckPlayMenuInternal(MediaItem item)
        {
            IPlayerContextManager pcm = ServiceRegistration.Get <IPlayerContextManager>();
            int numOpen = pcm.NumActivePlayerContexts;

            if (numOpen == 0)
            {
                // Asynchronously leave the current workflow state because we're called from a workflow model method
                IThreadPool threadPool = ServiceRegistration.Get <IThreadPool>();
                threadPool.Add(() =>
                {
                    LeaveCheckQueryPlayActionSingleItemState();
                    CheckEdition(item);
                    //CheckResumeAction(item);
                });
                return;
            }
            _playMenuItems = new ItemsList();
            AVType avType   = pcm.GetTypeOfMediaItem(item);
            int    numAudio = pcm.GetPlayerContextsByAVType(AVType.Audio).Count();
            int    numVideo = pcm.GetPlayerContextsByAVType(AVType.Video).Count();

            switch (avType)
            {
            case AVType.Audio:
            {
                ListItem playItem = new ListItem(Consts.KEY_NAME, Consts.RES_PLAY_AUDIO_ITEM)
                {
                    Command = new MethodDelegateCommand(() =>
                        {
                            LeaveCheckQueryPlayActionSingleItemState();
                            CheckEdition(item);
                            //CheckResumeAction(item);
                        })
                };
                _playMenuItems.Add(playItem);
                if (numAudio > 0)
                {
                    ListItem enqueueItem = new ListItem(Consts.KEY_NAME, Consts.RES_ENQUEUE_AUDIO_ITEM)
                    {
                        Command = new AsyncMethodDelegateCommand(() =>
                            {
                                LeaveCheckQueryPlayActionSingleItemState();
                                return(PlayOrEnqueueItem(item, false, PlayerContextConcurrencyMode.None));
                            })
                    };
                    _playMenuItems.Add(enqueueItem);
                }
                if (numVideo > 0)
                {
                    ListItem playItemConcurrently = new ListItem(Consts.KEY_NAME, Consts.RES_MUTE_VIDEO_PLAY_AUDIO_ITEM)
                    {
                        Command = new AsyncMethodDelegateCommand(() =>
                            {
                                LeaveCheckQueryPlayActionSingleItemState();
                                return(PlayOrEnqueueItem(item, true, PlayerContextConcurrencyMode.ConcurrentVideo));
                            })
                    };
                    _playMenuItems.Add(playItemConcurrently);
                }
            }
            break;

            case AVType.Video:
            {
                ListItem playItem = new ListItem(Consts.KEY_NAME, Consts.RES_PLAY_VIDEO_IMAGE_ITEM)
                {
                    Command = new MethodDelegateCommand(() =>
                        {
                            LeaveCheckQueryPlayActionSingleItemState();
                            CheckEdition(item);
                            //CheckResumeAction(item);
                        })
                };
                _playMenuItems.Add(playItem);
                if (numVideo > 0)
                {
                    ListItem enqueueItem = new ListItem(Consts.KEY_NAME, Consts.RES_ENQUEUE_VIDEO_IMAGE_ITEM)
                    {
                        Command = new AsyncMethodDelegateCommand(() =>
                            {
                                LeaveCheckQueryPlayActionSingleItemState();
                                return(PlayOrEnqueueItem(item, false, PlayerContextConcurrencyMode.None));
                            })
                    };
                    _playMenuItems.Add(enqueueItem);
                }
                if (numAudio > 0)
                {
                    ListItem playItem_A = new ListItem(Consts.KEY_NAME, Consts.RES_PLAY_VIDEO_IMAGE_ITEM_MUTED_CONCURRENT_AUDIO)
                    {
                        Command = new AsyncMethodDelegateCommand(() =>
                            {
                                LeaveCheckQueryPlayActionSingleItemState();
                                return(PlayOrEnqueueItem(item, true, PlayerContextConcurrencyMode.ConcurrentAudio));
                            })
                    };
                    _playMenuItems.Add(playItem_A);
                }
                if (numVideo > 0)
                {
                    ListItem playItem_V = new ListItem(Consts.KEY_NAME, Consts.RES_PLAY_VIDEO_IMAGE_ITEM_PIP)
                    {
                        Command = new AsyncMethodDelegateCommand(() =>
                            {
                                LeaveCheckQueryPlayActionSingleItemState();
                                return(PlayOrEnqueueItem(item, true, PlayerContextConcurrencyMode.ConcurrentVideo));
                            })
                    };
                    _playMenuItems.Add(playItem_V);
                }
            }
            break;

            default:
            {
                IDialogManager dialogManager  = ServiceRegistration.Get <IDialogManager>();
                Guid           dialogHandleId = dialogManager.ShowDialog(Consts.RES_SYSTEM_INFORMATION, Consts.RES_CANNOT_PLAY_ITEM_DIALOG_TEXT,
                                                                         DialogType.OkDialog, false, DialogButtonType.Ok);
                _dialogCloseWatcher = new DialogCloseWatcher(this, dialogHandleId, dialogResult => LeaveCheckQueryPlayActionSingleItemState());
            }
            break;
            }
            IScreenManager screenManager = ServiceRegistration.Get <IScreenManager>();

            screenManager.ShowDialog(Consts.DIALOG_PLAY_MENU, (dialogName, dialogInstanceId) => LeaveCheckQueryPlayActionSingleItemState());
        }