/// <summary>
        /// Goes through each Media object within PlayableMediaItems and updates Playstate for each individually
        /// </summary>
        private void UpdatePlayStates(BasePlaybackController controller, PlaybackStateEventArgs args)
        {
            string currentFile = CurrentFile;

            for (int i = 0; i < MediaItems.Count(); i++)
            {
                Media media = MediaItems.ElementAt(i);

                bool isCurrentMedia = i == CurrentMediaIndex;

                long currentPositionTicks    = 0;
                int  currentPlaylistPosition = 0;

                if (isCurrentMedia)
                {
                    // If this is where playback is, update position and playlist
                    currentPlaylistPosition            = controller.GetPlayableFiles(media).ToList().IndexOf(currentFile);
                    media.PlaybackStatus.PositionTicks = currentPositionTicks = args.Position;
                }

                Application.CurrentInstance.UpdatePlayState(media, media.PlaybackStatus, controller.IsPaused, EnablePlayStateSaving);

                if (isCurrentMedia)
                {
                    break;
                }
            }

            HasUpdatedPlayState = true;
        }
 private void UpdateCurrentMediaPlayState(BasePlaybackController controller, PlaybackStateEventArgs args)
 {
     if (CurrentMedia != null)
     {
         CurrentMedia.PlaybackStatus.PositionTicks = args.Position;
         Application.CurrentInstance.UpdatePlayState(CurrentMedia, CurrentMedia.PlaybackStatus, controller.IsPaused, EnablePlayStateSaving);
     }
 }
Ejemplo n.º 3
0
        internal void OnPlaybackFinished(BasePlaybackController controller, PlaybackStateEventArgs args)
        {
            if (args.Item == this && HasMediaItems)
            {
                // If there's still a valid position, fire progress one last time
                if (args.Position > 0)
                {
                    OnProgress(controller, args);
                }
                //update any previously played items to fully watched
                for (var i = 0; i < args.Item.CurrentMediaIndex; i++)
                {
                    OnItemFinished(args.Item.MediaItems.ElementAt(i), long.MaxValue);
                }

                //and then the current one with current state
                OnItemFinished(CurrentMedia, args.Position);
            }

            PlaybackStoppedByUser = args.StoppedByUser;


            PlayState = PlayableItemPlayState.Stopped;

            //DisplayUtil.RevertRefreshRate();

            // Fire finished event
            if (_PlaybackFinished != null)
            {
                Async.Queue(Async.ThreadPoolName.PlayableItemPlaybackFinished, () =>
                {
                    _PlaybackFinished(this, new GenericEventArgs <PlayableItem>()
                    {
                        Item = this
                    });
                });
            }

            if (RaiseGlobalPlaybackEvents)
            {
                Application.CurrentInstance.RunPostPlayProcesses(this);
            }

            if (UnmountISOAfterPlayback)
            {
                Application.CurrentInstance.UnmountIso();
            }
        }
Ejemplo n.º 4
0
        internal void OnPlaybackFinished(BasePlaybackController controller, PlaybackStateEventArgs args)
        {
            if (args.Item == this)
            {
                // If there's still a valid position, fire progress one last time
                if (args.Position > 0)
                {
                    OnProgress(controller, args);
                }

                PlaybackStoppedByUser = args.StoppedByUser;

                MarkWatchedIfNeeded();
            }

            PlayState = PlayableItemPlayState.Stopped;

            // Fire finished event
            if (_PlaybackFinished != null)
            {
                Async.Queue("PlayableItem PlaybackFinished", () =>
                {
                    _PlaybackFinished(this, new GenericEventArgs <PlayableItem>()
                    {
                        Item = this
                    });
                });
            }

            if (RaiseGlobalPlaybackEvents)
            {
                Application.CurrentInstance.RunPostPlayProcesses(this);
            }

            if (UnmountISOAfterPlayback)
            {
                Application.CurrentInstance.UnmountIso();
            }
        }
        internal void OnProgress(BasePlaybackController controller, PlaybackStateEventArgs args)
        {
            CurrentFileIndex  = args.CurrentFileIndex;
            CurrentMediaIndex = args.CurrentMediaIndex;

            PlayState = PlayableItemPlayState.Playing;

            UpdateCurrentMediaPlayState(controller, args);

            if (_Progress != null)
            {
                try
                {
                    _Progress(this, new GenericEventArgs <PlayableItem>()
                    {
                        Item = this
                    });
                }
                catch (Exception ex)
                {
                    Logger.ReportException("PlayableItem Progress event listener had an error: ", ex);
                }
            }
        }