コード例 #1
0
ファイル: PreservePiP.cs プロジェクト: joconno4/MediaPortal-2
    public override void PrepareVideoPlayer(IPlayerManager playerManager, IList<IPlayerContext> playerContexts, PlayerContextConcurrencyMode concurrencyMode, Guid mediaModuleId,
        out IPlayerSlotController slotController, ref int audioSlotIndex, ref int currentPlayerIndex)
    {
        int numActive = playerContexts.Count;
        switch (concurrencyMode)
        {
          case PlayerContextConcurrencyMode.ConcurrentVideo:
            if (numActive >= 1 && playerContexts[0].AVType == AVType.Video)
            { // The primary slot is a video player slot
              if (numActive == 1)
              {
                int slotIndex;
                playerManager.OpenSlot(out slotIndex, out slotController);
                playerManager.SwitchSlots();
              }
              else // numActive > 1
              {
                IPlayerContext pc = playerContexts[0];
                pc.Reset(); // Necessary to reset the player context to disable the auto close function (pc.CloseWhenFinished)
                playerManager.ResetSlot(PlayerManagerConsts.PRIMARY_SLOT, out slotController);
              }

              audioSlotIndex = PlayerManagerConsts.PRIMARY_SLOT;
              currentPlayerIndex = PlayerManagerConsts.PRIMARY_SLOT;
              return;
            }
            break;
        }
      // All other cases are the same as in the default player open strategy
      base.PrepareVideoPlayer(playerManager, playerContexts, concurrencyMode, mediaModuleId, out slotController, ref audioSlotIndex, ref currentPlayerIndex);
    }
コード例 #2
0
        protected void PrepareState(NavigationContext context)
        {
            Guid workflowStateId = context.WorkflowState.StateId;

            if (workflowStateId == Consts.WF_STATE_ID_PLAY_OR_ENQUEUE_ITEMS)
            {
                AVType            avType = (AVType)context.GetContextVariable(KEY_AV_TYPE, false);
                GetMediaItemsDlgt getMediaItemsFunction = (GetMediaItemsDlgt)context.GetContextVariable(KEY_GET_MEDIA_ITEMS_FUNCTION, false);
                bool doPlay = (bool)context.GetContextVariable(KEY_DO_PLAY, false);
                PlayerContextConcurrencyMode concurrencyMode = (PlayerContextConcurrencyMode)context.GetContextVariable(KEY_CONCURRENCY_MODE, false);
                PlayOrEnqueueItemsInternal(getMediaItemsFunction, avType, doPlay, concurrencyMode);
            }
            else if (workflowStateId == Consts.WF_STATE_ID_CHECK_RESUME_SINGLE_ITEM)
            {
                MediaItem item = (MediaItem)context.GetContextVariable(KEY_MEDIA_ITEM, false);
                CheckResumeMenuInternal(item);
            }
            else if (workflowStateId == Consts.WF_STATE_ID_CHECK_QUERY_PLAYACTION_SINGLE_ITEM)
            {
                MediaItem item = (MediaItem)context.GetContextVariable(KEY_MEDIA_ITEM, false);
                CheckPlayMenuInternal(item);
            }
            else if (workflowStateId == Consts.WF_STATE_ID_CHECK_QUERY_PLAYACTION_MULTIPLE_ITEMS)
            {
                GetMediaItemsDlgt getMediaItemsFunction = (GetMediaItemsDlgt)context.GetContextVariable(KEY_GET_MEDIA_ITEMS_FUNCTION, false);
                AVType            avType = (AVType)context.GetContextVariable(KEY_AV_TYPE, false);
                CheckPlayMenuInternal(getMediaItemsFunction, avType);
            }
            else if (workflowStateId == Consts.WF_STATE_ID_QUERY_AV_TYPE_CHECK_QUERY_PLAYACTION_MULTIPLE_ITEMS)
            {
                GetMediaItemsDlgt getMediaItemsFunction = (GetMediaItemsDlgt)context.GetContextVariable(KEY_GET_MEDIA_ITEMS_FUNCTION, false);
                CheckQueryPlayAction_ShowMediaTypeChoice(getMediaItemsFunction);
            }
        }
コード例 #3
0
        public override IPlayerSlotController PrepareVideoPlayerSlotController(IPlayerManager playerManager, PlayerContextManager playerContextManager,
                                                                               PlayerContextConcurrencyMode concurrencyMode, out bool makePrimaryPlayer, out int audioPlayerSlotIndex, out int currentPlayerSlotIndex)
        {
            int numActive = playerContextManager.NumActivePlayerContexts;

            switch (concurrencyMode)
            {
            case PlayerContextConcurrencyMode.ConcurrentVideo:
                IList <IPlayerContext> playerContexts = playerContextManager.PlayerContexts;
                if (numActive >= 1 && playerContexts[PlayerContextIndex.PRIMARY].AVType == AVType.Video)
                { // The primary slot is a video player slot
                    IPlayerSlotController result;
                    if (numActive == 1)
                    {
                        result            = playerManager.OpenSlot();
                        makePrimaryPlayer = true;
                    }
                    else // numActive > 1
                    {
                        IPlayerContext pc = playerContexts[PlayerContextIndex.PRIMARY];
                        result            = pc.Revoke(); // Necessary to revoke the player context to disable the auto close function (pc.CloseWhenFinished)
                        makePrimaryPlayer = true;
                    }

                    audioPlayerSlotIndex   = PlayerContextIndex.PRIMARY;
                    currentPlayerSlotIndex = PlayerContextIndex.PRIMARY;
                    return(result);
                }
                break;
            }
            // All other cases are handled the same as in the default player open strategy
            return(base.PrepareVideoPlayerSlotController(playerManager, playerContextManager, concurrencyMode, out makePrimaryPlayer,
                                                         out audioPlayerSlotIndex, out currentPlayerSlotIndex));
        }
コード例 #4
0
    public override IPlayerSlotController PrepareVideoPlayerSlotController(IPlayerManager playerManager, PlayerContextManager playerContextManager,
        PlayerContextConcurrencyMode concurrencyMode, out bool makePrimaryPlayer, out int audioPlayerSlotIndex, out int currentPlayerSlotIndex)
    {
        int numActive = playerContextManager.NumActivePlayerContexts;
        switch (concurrencyMode)
        {
          case PlayerContextConcurrencyMode.ConcurrentVideo:
            IList<IPlayerContext> playerContexts = playerContextManager.PlayerContexts;
            if (numActive >= 1 && playerContexts[PlayerContextIndex.PRIMARY].AVType == AVType.Video)
            { // The primary slot is a video player slot
              IPlayerSlotController result;
              if (numActive == 1)
              {
                result = playerManager.OpenSlot();
                makePrimaryPlayer = true;
              }
              else // numActive > 1
              {
                IPlayerContext pc = playerContexts[PlayerContextIndex.PRIMARY];
                result = pc.Revoke(); // Necessary to revoke the player context to disable the auto close function (pc.CloseWhenFinished)
                makePrimaryPlayer = true;
              }

              audioPlayerSlotIndex = PlayerContextIndex.PRIMARY;
              currentPlayerSlotIndex = PlayerContextIndex.PRIMARY;
              return result;
            }
            break;
        }
      // All other cases are handled the same as in the default player open strategy
      return base.PrepareVideoPlayerSlotController(playerManager, playerContextManager, concurrencyMode, out makePrimaryPlayer,
          out audioPlayerSlotIndex, out currentPlayerSlotIndex);
    }
コード例 #5
0
        public async Task <bool> StartTimeshiftAsync(int slotIndex, IChannel channel)
        {
            if (TimeshiftControl == null || channel == null)
            {
                return(false);
            }

            ServiceRegistration.Get <ILogger>().Debug("SlimTvHandler: StartTimeshift slot {0} for channel '{1}'", slotIndex, channel.Name);

            int newSlotIndex = GetMatchingSlotIndex(slotIndex);

            if (_slotContexes[newSlotIndex].Channel != null && _slotContexes[newSlotIndex].Channel.MediaType != channel.MediaType)
            {
                // Switching between TV and radio - must close old player and start brand new one
                IPlayerContext playerContext = existingPlayerContext(newSlotIndex);
                if (playerContext == null)
                {
                    return(false);
                }
                playerContext.Close();
                await StopTimeshiftAsync(newSlotIndex);
            }
            var result = await TimeshiftControl.StartTimeshiftAsync(newSlotIndex, channel);

            IList <MultipleMediaItemAspect> pras;
            MediaItem timeshiftMediaItem = result.Result;

            if (result.Success && timeshiftMediaItem != null && MediaItemAspect.TryGetAspects(timeshiftMediaItem.Aspects, ProviderResourceAspect.Metadata, out pras))
            {
                string newAccessorPath = (string)pras[0].GetAttributeValue(ProviderResourceAspect.ATTR_RESOURCE_ACCESSOR_PATH);

                // if slot was empty, start a new player
                if (_slotContexes[newSlotIndex].AccessorPath == null)
                {
                    AddOrUpdateTimeshiftContext(timeshiftMediaItem as LiveTvMediaItem, channel);
                    PlayerContextConcurrencyMode playMode = GetMatchingPlayMode();
                    await PlayItemsModel.PlayOrEnqueueItem(timeshiftMediaItem, true, playMode);
                }
                else
                {
                    try
                    {
                        _slotContexes[newSlotIndex].CardChanging = true;
                        UpdateExistingMediaItem(timeshiftMediaItem, newSlotIndex);
                    }
                    finally
                    {
                        _slotContexes[newSlotIndex].CardChanging = false;
                    }
                }
                _slotContexes[newSlotIndex].AccessorPath = newAccessorPath;
                _slotContexes[newSlotIndex].Channel      = channel;
            }
            return(result.Success);
        }
コード例 #6
0
ファイル: Default.cs プロジェクト: joconno4/MediaPortal-2
 public virtual void PrepareVideoPlayer(IPlayerManager playerManager, IList<IPlayerContext> playerContexts, PlayerContextConcurrencyMode concurrencyMode, Guid mediaModuleId,
     out IPlayerSlotController slotController, ref int audioSlotIndex, ref int currentPlayerIndex)
 {
     int numActive = playerContexts.Count;
     int slotIndex;
     switch (concurrencyMode)
     {
       case PlayerContextConcurrencyMode.ConcurrentAudio:
         if (numActive > 1 && playerContexts[1].AVType == AVType.Audio)
         { // The secondary slot is an audio player slot
           slotIndex = PlayerManagerConsts.PRIMARY_SLOT;
           IPlayerContext pc = playerContexts[0];
           pc.Reset(); // Necessary to reset the player context to disable the auto close function (pc.CloseWhenFinished)
           playerManager.ResetSlot(slotIndex, out slotController);
           audioSlotIndex = PlayerManagerConsts.SECONDARY_SLOT;
         }
         else if (numActive == 1 && playerContexts[0].AVType == AVType.Audio)
         { // The primary slot is an audio player slot
           playerManager.OpenSlot(out slotIndex, out slotController);
           // Make new video slot the primary slot
           playerManager.SwitchSlots();
           audioSlotIndex = PlayerManagerConsts.SECONDARY_SLOT;
         }
         else
         { // No audio slot available
           playerManager.CloseAllSlots();
           playerManager.OpenSlot(out slotIndex, out slotController);
           audioSlotIndex = PlayerManagerConsts.PRIMARY_SLOT;
         }
         break;
       case PlayerContextConcurrencyMode.ConcurrentVideo:
         if (numActive >= 1 && playerContexts[0].AVType == AVType.Video)
         { // The primary slot is a video player slot
           if (numActive > 1)
             playerManager.CloseSlot(PlayerManagerConsts.SECONDARY_SLOT);
           playerManager.OpenSlot(out slotIndex, out slotController);
           audioSlotIndex = PlayerManagerConsts.PRIMARY_SLOT;
         }
         else
         {
           playerManager.CloseAllSlots();
           playerManager.OpenSlot(out slotIndex, out slotController);
           audioSlotIndex = PlayerManagerConsts.PRIMARY_SLOT;
         }
         break;
       default:
         // Don't enable concurrent controllers: Close all except the primary slot controller
         playerManager.CloseAllSlots();
         playerManager.OpenSlot(out slotIndex, out slotController);
         audioSlotIndex = PlayerManagerConsts.PRIMARY_SLOT;
         break;
     }
   currentPlayerIndex = slotIndex;
 }
コード例 #7
0
        protected void PlayOrEnqueueItemsInternal(GetMediaItemsDlgt getMediaItemsFunction, AVType avType,
                                                  bool play, PlayerContextConcurrencyMode concurrencyMode)
        {
            IPlayerContext pc = PreparePlayerContext(avType, play, concurrencyMode);

            if (pc == null)
            {
                return;
            }

            // Adding items to playlist must be executed asynchronously - we will show a progress dialog where we aren't allowed
            // to block the input thread.
            IThreadPool threadPool = ServiceRegistration.Get <IThreadPool>();

            threadPool.Add(() => AsyncAddToPlaylist(pc, getMediaItemsFunction, play));
        }
コード例 #8
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);
        }
コード例 #9
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));
        }
コード例 #10
0
        /// <summary>
        /// Depending on parameter <paramref name="play"/>, plays or enqueues the media items of type <paramref name="avType"/>
        /// returned by the given <paramref name="getMediaItemsFunction"/>.
        /// This method can also be called from other models.
        /// </summary>
        /// <param name="getMediaItemsFunction">Function returning the media items to be played.</param>
        /// <param name="avType">AV type of media items to be played.</param>
        /// <param name="play">If <c>true</c>, plays the specified items, else enqueues it.</param>
        /// <param name="concurrencyMode">Determines if the media item will be played or enqueued in concurrency mode.</param>
        public static void PlayOrEnqueueItems(GetMediaItemsDlgt getMediaItemsFunction, AVType avType,
                                              bool play, PlayerContextConcurrencyMode concurrencyMode)
        {
            IWorkflowManager workflowManager = ServiceRegistration.Get <IWorkflowManager>();

            workflowManager.NavigatePush(Consts.WF_STATE_ID_PLAY_OR_ENQUEUE_ITEMS, new NavigationContextConfig
            {
                AdditionalContextVariables = new Dictionary <string, object>
                {
                    { KEY_GET_MEDIA_ITEMS_FUNCTION, getMediaItemsFunction },
                    { KEY_AV_TYPE, avType },
                    { KEY_DO_PLAY, play },
                    { KEY_CONCURRENCY_MODE, concurrencyMode },
                }
            });
        }
コード例 #11
0
        public bool WatchRecordingFromBeginning(IProgram program)
        {
            string fileOrStream;

            if (ScheduleControl.GetRecordingFileOrStream(program, out fileOrStream))
            {
                IChannel channel;
                if (ChannelAndGroupInfo.GetChannel(program.ChannelId, out channel))
                {
                    MediaItem recordig = SlimTvMediaItemBuilder.CreateRecordingMediaItem(0, fileOrStream, program, channel);
                    PlayerContextConcurrencyMode playMode = GetMatchingPlayMode();
                    PlayItemsModel.PlayOrEnqueueItem(recordig, true, playMode);
                    return(true);
                }
            }
            return(false);
        }
コード例 #12
0
        protected async Task PlayOrEnqueueItemsInternal(GetMediaItemsDlgt getMediaItemsFunction, AVType avType,
                                                        bool play, PlayerContextConcurrencyMode concurrencyMode)
        {
            IPlayerContext pc = PreparePlayerContext(avType, play, concurrencyMode);

            if (pc == null)
            {
                return;
            }

            // Adding items to playlist must be executed asynchronously - we will show a progress dialog where we aren't allowed
            // to block the input thread.
            //await Task.Yield();
            await Task.Run(async() =>
            {
                await AsyncAddToPlaylist(pc, getMediaItemsFunction, play);
            });
        }
コード例 #13
0
        public bool StartTimeshift(int slotIndex, IChannel channel)
        {
            if (TimeshiftControl == null || channel == null)
            {
                return(false);
            }

            ServiceRegistration.Get <ILogger>().Debug("SlimTvHandler: StartTimeshift slot {0} for channel '{1}'", slotIndex, channel.Name);

            int       newSlotIndex = GetMatchingSlotIndex(slotIndex);
            MediaItem timeshiftMediaItem;
            bool      result = TimeshiftControl.StartTimeshift(newSlotIndex, channel, out timeshiftMediaItem);
            IList <MultipleMediaItemAspect> pras;

            if (result && timeshiftMediaItem != null && MediaItemAspect.TryGetAspects(timeshiftMediaItem.Aspects, ProviderResourceAspect.Metadata, out pras))
            {
                string newAccessorPath = (string)pras[0].GetAttributeValue(ProviderResourceAspect.ATTR_RESOURCE_ACCESSOR_PATH);

                // if slot was empty, start a new player
                if (_slotContexes[newSlotIndex].AccessorPath == null)
                {
                    AddOrUpdateTimeshiftContext(timeshiftMediaItem as LiveTvMediaItem, channel);
                    PlayerContextConcurrencyMode playMode = GetMatchingPlayMode();
                    PlayItemsModel.PlayOrEnqueueItem(timeshiftMediaItem, true, playMode);
                }
                else
                {
                    try
                    {
                        _slotContexes[newSlotIndex].CardChanging = true;
                        UpdateExistingMediaItem(timeshiftMediaItem);
                    }
                    finally
                    {
                        _slotContexes[newSlotIndex].CardChanging = false;
                    }
                }
                _slotContexes[newSlotIndex].AccessorPath = newAccessorPath;
                _slotContexes[newSlotIndex].Channel      = channel;
            }

            return(result);
        }
コード例 #14
0
        public bool StartTimeshift(int slotIndex, IChannel channel)
        {
            if (TimeshiftControl == null || channel == null)
            {
                return(false);
            }

            int       newSlotIndex = GetMatchingSlotIndex(slotIndex);
            MediaItem timeshiftMediaItem;
            bool      result = TimeshiftControl.StartTimeshift(newSlotIndex, channel, out timeshiftMediaItem);

            if (result && timeshiftMediaItem != null)
            {
                string newAccessorPath =
                    (string)timeshiftMediaItem.Aspects[ProviderResourceAspect.ASPECT_ID].GetAttributeValue(
                        ProviderResourceAspect.ATTR_RESOURCE_ACCESSOR_PATH);

                // if slot was empty, start a new player
                if (_slotContexes[newSlotIndex].AccessorPath == null)
                {
                    AddTimeshiftContext(timeshiftMediaItem as LiveTvMediaItem, channel);
                    PlayerContextConcurrencyMode playMode = GetMatchingPlayMode();
                    PlayItemsModel.PlayOrEnqueueItem(timeshiftMediaItem, true, playMode);
                }
                else
                {
                    try
                    {
                        _slotContexes[newSlotIndex].CardChanging = true;
                        UpdateExistingMediaItem(timeshiftMediaItem);
                    }
                    finally
                    {
                        _slotContexes[newSlotIndex].CardChanging = false;
                    }
                }
                _slotContexes[newSlotIndex].AccessorPath = newAccessorPath;
                _slotContexes[newSlotIndex].Channel      = channel;
            }

            return(result);
        }
コード例 #15
0
        public IPlayerContext OpenVideoPlayerContext(Guid mediaModuleId, string name, PlayerContextConcurrencyMode concurrencyMode,
                                                     Guid currentlyPlayingWorkflowStateId, Guid fullscreenContentWorkflowStateId)
        {
            IOpenPlayerStrategy strategy      = GetOpenPlayerStrategy();
            IPlayerManager      playerManager = ServiceRegistration.Get <IPlayerManager>();

            lock (playerManager.SyncObj)
            {
                int  audioPlayerSlotIndex;
                int  currentPlayerSlotIndex;
                bool makePrimaryPlayer;
                IPlayerSlotController slotController = strategy.PrepareVideoPlayerSlotController(playerManager, this, concurrencyMode,
                                                                                                 out makePrimaryPlayer, out audioPlayerSlotIndex, out currentPlayerSlotIndex);
                slotController.Closed += OnPlayerSlotControllerClosed;
                if (makePrimaryPlayer)
                {
                    PlayerContext oldPrimaryPC = GetPlayerContextInternal(PlayerContextIndex.PRIMARY);
                    if (oldPrimaryPC != null)
                    {
                        oldPrimaryPC.IsPrimaryPlayerContext = false;
                    }
                }
                PlayerContext result = new PlayerContext(slotController, mediaModuleId, name, AVType.Video, currentlyPlayingWorkflowStateId, fullscreenContentWorkflowStateId);
                if (makePrimaryPlayer)
                {
                    result.IsPrimaryPlayerContext = true;
                }
                CleanupPlayerContexts();
                IList <IPlayerContext> playerContexts = PlayerContexts;
                int lastPlayerContextIndex            = playerContexts.Count - 1;
                if (currentPlayerSlotIndex > lastPlayerContextIndex)
                {
                    currentPlayerSlotIndex = lastPlayerContextIndex;
                }
                if (audioPlayerSlotIndex > lastPlayerContextIndex)
                {
                    audioPlayerSlotIndex = lastPlayerContextIndex;
                }
                PlayerContextManagerMessaging.SendUpdatePlayerRolesMessage(playerContexts[currentPlayerSlotIndex], playerContexts[audioPlayerSlotIndex]);
                return(result);
            }
        }
コード例 #16
0
ファイル: Default.cs プロジェクト: HAF-Blade/MediaPortal-2
 public virtual IPlayerSlotController PrepareVideoPlayerSlotController(IPlayerManager playerManager, PlayerContextManager playerContextManager,
     PlayerContextConcurrencyMode concurrencyMode, out bool makePrimaryPlayer, out int audioPlayerSlotIndex, out int currentPlayerSlotIndex)
 {
   IList<IPlayerContext> playerContexts = playerContextManager.PlayerContexts;
   int numActive = playerContexts.Count;
   IPlayerSlotController result;
   switch (concurrencyMode)
   {
     case PlayerContextConcurrencyMode.ConcurrentAudio:
       if (numActive > 1 && playerContexts[PlayerContextIndex.SECONDARY].AVType == AVType.Audio)
       { // The secondary slot is an audio player slot
         IPlayerContext playerContext = playerContexts[PlayerContextIndex.PRIMARY];
         result = playerContext.Revoke();
         makePrimaryPlayer = true;
         audioPlayerSlotIndex = PlayerContextIndex.SECONDARY;
       }
       else if (numActive == 1 && playerContexts[PlayerContextIndex.PRIMARY].AVType == AVType.Audio)
       { // The primary slot is an audio player slot
         result = playerManager.OpenSlot();
         makePrimaryPlayer = true;
         audioPlayerSlotIndex = PlayerContextIndex.SECONDARY;
       }
       else
       { // No audio slot available
         playerContextManager.CloseAllPlayerContexts();
         result = playerManager.OpenSlot();
         makePrimaryPlayer = true;
         audioPlayerSlotIndex = PlayerContextIndex.PRIMARY;
       }
       break;
     case PlayerContextConcurrencyMode.ConcurrentVideo:
       if (numActive >= 1 && playerContexts[PlayerContextIndex.PRIMARY].AVType == AVType.Video)
       { // The primary slot is a video player slot
         if (numActive > 1)
         {
           IPlayerContext pcSecondary = playerContextManager.GetPlayerContext(PlayerContextIndex.SECONDARY);
           pcSecondary.Close();
         }
         result = playerManager.OpenSlot();
         makePrimaryPlayer = false;
         audioPlayerSlotIndex = PlayerContextIndex.PRIMARY;
       }
       else
       {
         playerContextManager.CloseAllPlayerContexts();
         result = playerManager.OpenSlot();
         makePrimaryPlayer = true;
         audioPlayerSlotIndex = PlayerContextIndex.PRIMARY;
       }
       break;
     default:
       // Don't enable concurrent controllers: Close all except the primary slot controller
       playerContextManager.CloseAllPlayerContexts();
       result = playerManager.OpenSlot();
       makePrimaryPlayer = true;
       audioPlayerSlotIndex = PlayerContextIndex.PRIMARY;
       break;
   }
   currentPlayerSlotIndex = makePrimaryPlayer ? PlayerContextIndex.PRIMARY : PlayerContextIndex.SECONDARY;
   return result;
 }
コード例 #17
0
        public IPlayerContext OpenVideoPlayerContext(Guid mediaModuleId, string name, PlayerContextConcurrencyMode concurrencyMode,
                                                     Guid currentlyPlayingWorkflowStateId, Guid fullscreenContentWorkflowStateId)
        {
            IOpenPlayerStrategy strategy      = GetOpenPlayerStrategy();
            IPlayerManager      playerManager = ServiceRegistration.Get <IPlayerManager>();

            lock (playerManager.SyncObj)
            {
                IList <IPlayerContext> playerContexts = GetPlayerContexts();
                IPlayerSlotController  slotController;
                int audioSlotIndex     = playerManager.AudioSlotIndex;
                int currentPlayerIndex = CurrentPlayerIndex;
                strategy.PrepareVideoPlayer(playerManager, playerContexts, concurrencyMode, mediaModuleId, out slotController, ref audioSlotIndex, ref currentPlayerIndex);
                PlayerContextManagerMessaging.SendUpdatePlayerRolesMessage(currentPlayerIndex, audioSlotIndex);
                return(new PlayerContext(this, slotController, mediaModuleId, name, AVType.Video,
                                         currentlyPlayingWorkflowStateId, fullscreenContentWorkflowStateId));
            }
        }
コード例 #18
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 void 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);

      ServiceRegistration.Get<IThreadPool>().Add(() => CompletePlayOrEnqueue(pc, play, resumeState));
    }
コード例 #19
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);
        }
コード例 #20
0
ファイル: Default.cs プロジェクト: zeroxist/MediaPortal-2
        public virtual IPlayerSlotController PrepareVideoPlayerSlotController(IPlayerManager playerManager, PlayerContextManager playerContextManager,
                                                                              PlayerContextConcurrencyMode concurrencyMode, out bool makePrimaryPlayer, out int audioPlayerSlotIndex, out int currentPlayerSlotIndex)
        {
            IList <IPlayerContext> playerContexts = playerContextManager.PlayerContexts;
            int numActive = playerContexts.Count;
            IPlayerSlotController result;

            switch (concurrencyMode)
            {
            case PlayerContextConcurrencyMode.ConcurrentAudio:
                if (numActive > 1 && playerContexts[PlayerContextIndex.SECONDARY].AVType == AVType.Audio)
                { // The secondary slot is an audio player slot
                    IPlayerContext playerContext = playerContexts[PlayerContextIndex.PRIMARY];
                    result               = playerContext.Revoke();
                    makePrimaryPlayer    = true;
                    audioPlayerSlotIndex = PlayerContextIndex.SECONDARY;
                }
                else if (numActive == 1 && playerContexts[PlayerContextIndex.PRIMARY].AVType == AVType.Audio)
                { // The primary slot is an audio player slot
                    result               = playerManager.OpenSlot();
                    makePrimaryPlayer    = true;
                    audioPlayerSlotIndex = PlayerContextIndex.SECONDARY;
                }
                else
                { // No audio slot available
                    playerContextManager.CloseAllPlayerContexts();
                    result               = playerManager.OpenSlot();
                    makePrimaryPlayer    = true;
                    audioPlayerSlotIndex = PlayerContextIndex.PRIMARY;
                }
                break;

            case PlayerContextConcurrencyMode.ConcurrentVideo:
                if (numActive >= 1 && playerContexts[PlayerContextIndex.PRIMARY].AVType == AVType.Video)
                { // The primary slot is a video player slot
                    if (numActive > 1)
                    {
                        IPlayerContext pcSecondary = playerContextManager.GetPlayerContext(PlayerContextIndex.SECONDARY);
                        pcSecondary.Close();
                    }
                    result               = playerManager.OpenSlot();
                    makePrimaryPlayer    = false;
                    audioPlayerSlotIndex = PlayerContextIndex.PRIMARY;
                }
                else
                {
                    playerContextManager.CloseAllPlayerContexts();
                    result               = playerManager.OpenSlot();
                    makePrimaryPlayer    = true;
                    audioPlayerSlotIndex = PlayerContextIndex.PRIMARY;
                }
                break;

            default:
                // Don't enable concurrent controllers: Close all except the primary slot controller
                playerContextManager.CloseAllPlayerContexts();
                result               = playerManager.OpenSlot();
                makePrimaryPlayer    = true;
                audioPlayerSlotIndex = PlayerContextIndex.PRIMARY;
                break;
            }
            currentPlayerSlotIndex = makePrimaryPlayer ? PlayerContextIndex.PRIMARY : PlayerContextIndex.SECONDARY;
            return(result);
        }
コード例 #21
0
 /// <summary>
 /// Depending on parameter <paramref name="play"/>, plays or enqueues the media items of type <paramref name="avType"/>
 /// returned by the given <paramref name="getMediaItemsFunction"/>.
 /// This method can also be called from other models.
 /// </summary>
 /// <param name="getMediaItemsFunction">Function returning the media items to be played.</param>
 /// <param name="avType">AV type of media items to be played.</param>
 /// <param name="play">If <c>true</c>, plays the specified items, else enqueues it.</param>
 /// <param name="concurrencyMode">Determines if the media item will be played or enqueued in concurrency mode.</param>
 public static void PlayOrEnqueueItems(GetMediaItemsDlgt getMediaItemsFunction, AVType avType,
     bool play, PlayerContextConcurrencyMode concurrencyMode)
 {
   IWorkflowManager workflowManager = ServiceRegistration.Get<IWorkflowManager>();
   workflowManager.NavigatePush(Consts.WF_STATE_ID_PLAY_OR_ENQUEUE_ITEMS, new NavigationContextConfig
     {
         AdditionalContextVariables = new Dictionary<string, object>
           {
               {KEY_GET_MEDIA_ITEMS_FUNCTION, getMediaItemsFunction},
               {KEY_AV_TYPE, avType},
               {KEY_DO_PLAY, play},
               {KEY_CONCURRENCY_MODE, concurrencyMode},
           }
     });
 }
コード例 #22
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;
 }
コード例 #23
0
    protected void PlayOrEnqueueItemsInternal(GetMediaItemsDlgt getMediaItemsFunction, AVType avType,
        bool play, PlayerContextConcurrencyMode concurrencyMode)
    {
      IPlayerContext pc = PreparePlayerContext(avType, play, concurrencyMode);
      if (pc == null)
        return;

      // Adding items to playlist must be executed asynchronously - we will show a progress dialog where we aren't allowed
      // to block the input thread.
      IThreadPool threadPool = ServiceRegistration.Get<IThreadPool>();
      threadPool.Add(() => AsyncAddToPlaylist(pc, getMediaItemsFunction, play));
    }
コード例 #24
0
 public IPlayerContext OpenVideoPlayerContext(Guid mediaModuleId, string name, PlayerContextConcurrencyMode concurrencyMode,
     Guid currentlyPlayingWorkflowStateId, Guid fullscreenContentWorkflowStateId)
 {
   IOpenPlayerStrategy strategy = GetOpenPlayerStrategy();
   IPlayerManager playerManager = ServiceRegistration.Get<IPlayerManager>();
   lock (playerManager.SyncObj)
   {
     IList<IPlayerContext> playerContexts = GetPlayerContexts();
     IPlayerSlotController slotController;
     int audioSlotIndex = playerManager.AudioSlotIndex;
     int currentPlayerIndex = CurrentPlayerIndex;
     strategy.PrepareVideoPlayer(playerManager, playerContexts, concurrencyMode, mediaModuleId, out slotController, ref audioSlotIndex, ref currentPlayerIndex);
     PlayerContextManagerMessaging.SendUpdatePlayerRolesMessage(currentPlayerIndex, audioSlotIndex);
     return new PlayerContext(this, slotController, mediaModuleId, name, AVType.Video,
         currentlyPlayingWorkflowStateId, fullscreenContentWorkflowStateId);
   }
 }
コード例 #25
0
        public override void PrepareVideoPlayer(IPlayerManager playerManager, IList <IPlayerContext> playerContexts, PlayerContextConcurrencyMode concurrencyMode, Guid mediaModuleId,
                                                out IPlayerSlotController slotController, ref int audioSlotIndex, ref int currentPlayerIndex)
        {
            int numActive = playerContexts.Count;

            switch (concurrencyMode)
            {
            case PlayerContextConcurrencyMode.ConcurrentVideo:
                if (numActive >= 1 && playerContexts[0].AVType == AVType.Video)
                { // The primary slot is a video player slot
                    if (numActive == 1)
                    {
                        int slotIndex;
                        playerManager.OpenSlot(out slotIndex, out slotController);
                        playerManager.SwitchSlots();
                    }
                    else // numActive > 1
                    {
                        IPlayerContext pc = playerContexts[0];
                        pc.Reset(); // Necessary to reset the player context to disable the auto close function (pc.CloseWhenFinished)
                        playerManager.ResetSlot(PlayerManagerConsts.PRIMARY_SLOT, out slotController);
                    }

                    audioSlotIndex     = PlayerManagerConsts.PRIMARY_SLOT;
                    currentPlayerIndex = PlayerManagerConsts.PRIMARY_SLOT;
                    return;
                }
                break;
            }
            // All other cases are the same as in the default player open strategy
            base.PrepareVideoPlayer(playerManager, playerContexts, concurrencyMode, mediaModuleId, out slotController, ref audioSlotIndex, ref currentPlayerIndex);
        }
コード例 #26
0
        public virtual void PrepareVideoPlayer(IPlayerManager playerManager, IList <IPlayerContext> playerContexts, PlayerContextConcurrencyMode concurrencyMode, Guid mediaModuleId,
                                               out IPlayerSlotController slotController, ref int audioSlotIndex, ref int currentPlayerIndex)
        {
            int numActive = playerContexts.Count;
            int slotIndex;

            switch (concurrencyMode)
            {
            case PlayerContextConcurrencyMode.ConcurrentAudio:
                if (numActive > 1 && playerContexts[1].AVType == AVType.Audio)
                { // The secondary slot is an audio player slot
                    slotIndex = PlayerManagerConsts.PRIMARY_SLOT;
                    IPlayerContext pc = playerContexts[0];
                    pc.Reset(); // Necessary to reset the player context to disable the auto close function (pc.CloseWhenFinished)
                    playerManager.ResetSlot(slotIndex, out slotController);
                    audioSlotIndex = PlayerManagerConsts.SECONDARY_SLOT;
                }
                else if (numActive == 1 && playerContexts[0].AVType == AVType.Audio)
                { // The primary slot is an audio player slot
                    playerManager.OpenSlot(out slotIndex, out slotController);
                    // Make new video slot the primary slot
                    playerManager.SwitchSlots();
                    audioSlotIndex = PlayerManagerConsts.SECONDARY_SLOT;
                }
                else
                { // No audio slot available
                    playerManager.CloseAllSlots();
                    playerManager.OpenSlot(out slotIndex, out slotController);
                    audioSlotIndex = PlayerManagerConsts.PRIMARY_SLOT;
                }
                break;

            case PlayerContextConcurrencyMode.ConcurrentVideo:
                if (numActive >= 1 && playerContexts[0].AVType == AVType.Video)
                { // The primary slot is a video player slot
                    if (numActive > 1)
                    {
                        playerManager.CloseSlot(PlayerManagerConsts.SECONDARY_SLOT);
                    }
                    playerManager.OpenSlot(out slotIndex, out slotController);
                    audioSlotIndex = PlayerManagerConsts.PRIMARY_SLOT;
                }
                else
                {
                    playerManager.CloseAllSlots();
                    playerManager.OpenSlot(out slotIndex, out slotController);
                    audioSlotIndex = PlayerManagerConsts.PRIMARY_SLOT;
                }
                break;

            default:
                // Don't enable concurrent controllers: Close all except the primary slot controller
                playerManager.CloseAllSlots();
                playerManager.OpenSlot(out slotIndex, out slotController);
                audioSlotIndex = PlayerManagerConsts.PRIMARY_SLOT;
                break;
            }
            currentPlayerIndex = slotIndex;
        }