/// <summary>
        /// Handles the PlaybackCompleted event of the _mediaPlayer control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="PlaybackStopEventArgs"/> instance containing the event data.</param>
        async void _mediaPlayer_PlaybackCompleted(object sender, PlaybackStopEventArgs e)
        {
            _mediaPlayer.MediaChanged -= _mediaPlayer_MediaChanged;
            _mediaPlayer.PlaybackCompleted -= _mediaPlayer_PlaybackCompleted;

            if (_timer != null)
            {
                _timer.Dispose();
                _timer = null;
            }

            if (e.EndingMedia != null)
            {
                var info = new PlaybackStopInfo
                {
                    ItemId = e.EndingMedia.Id,
                    UserId = _apiClient.CurrentUserId,
                    PositionTicks = e.EndingPositionTicks
                };

                try
                {
                    await _apiClient.ReportPlaybackStoppedAsync(info);
                }
                catch (Exception ex)
                {
                    _logger.ErrorException("Error sending playback stopped checking for {0}", ex, e.EndingMedia.Name);
                }
            }
        }
        internal async void OnPlaybackStopped(PlayableItem media, long? positionTicks, TrackCompletionReason reason, int? newTrackIndex)
        {
            DisposeMount(media);

            if (reason == TrackCompletionReason.Ended || reason == TrackCompletionReason.ChangeTrack)
            {
                var nextIndex = newTrackIndex ?? (CurrentPlaylistIndex + 1);

                if (nextIndex < CurrentPlayOptions.Items.Count)
                {
                    await PlayTrack(nextIndex, null);
                    return;
                }
            }

            DisposePlayer();

            try
            {
                await _apiClient.StopTranscodingProcesses(_apiClient.DeviceId);
            }
            catch
            {

            }

            var args = new PlaybackStopEventArgs
            {
                Player = this,
                Playlist = _playlist,
                EndingMedia = media.OriginalItem,
                EndingPositionTicks = positionTicks

            };

            EventHelper.FireEventIfNotNull(PlaybackCompleted, this, args, _logger);

            _playbackManager.ReportPlaybackCompleted(args);
        }
        /// <summary>
        /// Reports the playback completed.
        /// </summary>
        /// <param name="eventArgs">The <see cref="PlaybackStopEventArgs"/> instance containing the event data.</param>
        public async void ReportPlaybackCompleted(PlaybackStopEventArgs eventArgs)
        {
            await _presentationManager.Window.Dispatcher.InvokeAsync(() => _presentationManager.WindowOverlay.SetResourceReference(FrameworkElement.StyleProperty, "WindowBackgroundContent"));

            EventHelper.QueueEventIfNotNull(PlaybackCompleted, this, eventArgs, _logger);
        }
 void _playbackManager_PlaybackCompleted(object sender, PlaybackStopEventArgs e)
 {
     Dispatcher.InvokeAsync(() => BackdropContainer.Visibility = Visibility.Visible);
 }
 void _playback_PlaybackCompleted(object sender, PlaybackStopEventArgs e)
 {
     _currentPlayingOwnerId = null;
 }
        /// <summary>
        /// Handles the Exited event of the CurrentProcess control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        void CurrentProcess_Exited(object sender, EventArgs e)
        {
            _currentProcess = null;

            _userInput.GlobalKeyDown -= KeyboardListener_KeyDown;

            var process = (Process)sender;

            var playlist = _playlist.ToList();
            var index = CurrentPlaylistIndex;
            var ticks = CurrentPositionTicks;

            process.Dispose();

            if (_currentIsoMount != null)
            {
                _currentIsoMount.Dispose();
                _currentIsoMount = null;
            }

            var media = index != -1 && playlist.Count > 0 ? playlist[index] : null;

            var args = new PlaybackStopEventArgs
            {
                Playlist = playlist,
                Player = this,
                EndingPlaylistIndex = index,
                EndingPositionTicks = ticks,
                EndingMedia = media
            };

            EventHelper.QueueEventIfNotNull(PlaybackCompleted, this, args, Logger);

            _playbackManager.ReportPlaybackCompleted(args);

            OnPlayerExited();
        }
 void PlaybackManager_PlaybackCompleted(object sender, PlaybackStopEventArgs e)
 {
     IsPlayingInternalVideo = false;
 }
 void _playback_PlaybackCompleted(object sender, PlaybackStopEventArgs e)
 {
     _lastInputTime = DateTime.Now;
 }
        /// <summary>
        /// Reports the playback completed.
        /// </summary>
        /// <param name="eventArgs">The <see cref="PlaybackStopEventArgs"/> instance containing the event data.</param>
        public async Task ReportPlaybackCompleted(PlaybackStopEventArgs eventArgs)
        {
            lock (_reporterLock)
            {
                if (_reporter != null)
                {
                    _reporter.Dispose();
                    _reporter = null;
                }
            }

            await _presentationManager.Window.Dispatcher.InvokeAsync(() => _presentationManager.WindowOverlay.SetResourceReference(FrameworkElement.StyleProperty, "WindowBackgroundContent"));

            EventHelper.QueueEventIfNotNull(PlaybackCompleted, this, eventArgs, _logger);
        }
        /// <summary>
        /// Handles the PlaybackCompleted event of the _mediaPlayer control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="eventArgs">The <see cref="PlaybackStopEventArgs"/> instance containing the event data.</param>
        async void _mediaPlayer_PlaybackCompleted(object sender, PlaybackStopEventArgs eventArgs)
        {
            _mediaPlayer.MediaChanged -= _mediaPlayer_MediaChanged;
            _mediaPlayer.PlaybackCompleted -= _mediaPlayer_PlaybackCompleted;

            var item = eventArgs.EndingMedia;
            if (item != null)
            {
                var apiClient = _connectionManager.GetApiClient(item);

                var stopInfo = new PlaybackStopInfo
                {
                    ItemId = item.Id,
                    PositionTicks = eventArgs.EndingPositionTicks
                };

                // Have to test this for null because external players are currently not supplying this
                // Also some players will play in contexts not currently supported by common playback managers, e.g. direct play of folder rips, and iso-mounted media
                // Remove when implemented
                if (eventArgs.StreamInfo != null)
                {
                    await _apiPlaybackManager.ReportPlaybackStopped(stopInfo, eventArgs.StreamInfo, item.ServerId, apiClient.CurrentUserId, false, apiClient);
                }
                else
                {
                    await apiClient.ReportPlaybackStoppedAsync(stopInfo);
                }
            }

            var timer = _timer;
            if (timer != null)
            {
                timer.Dispose();
                _timer = null;
            }
        }
        void _vlcControl_Stopped(VlcControl sender, VlcEventArgs<EventArgs> e)
        {
            var playlist = _playlist.ToList();
            var index = CurrentPlaylistIndex;
            var ticks = CurrentPositionTicks;

            DisposePlayer();

            var media = index != -1 && playlist.Count > 0 ? playlist[index] : null;

            var args = new PlaybackStopEventArgs
            {
                Playlist = playlist,
                Player = this,
                EndingPlaylistIndex = index,
                EndingPositionTicks = ticks,
                EndingMedia = media
            };

            EventHelper.QueueEventIfNotNull(PlaybackCompleted, this, args, _logger);

            _playbackManager.ReportPlaybackCompleted(args);
        }
 async void _playbackManager_PlaybackCompleted(object sender, PlaybackStopEventArgs e)
 {
     await _nav.NavigateBack();
 }
        async void _playbackManager_PlaybackCompleted(object sender, PlaybackStopEventArgs e)
        {
            if (_infoWindow != null)
            {
                Dispatcher.Invoke(() =>
                {
                    _infoWindow.Close();

                    _infoWindow = null;
                });
            }

            await _nav.NavigateBack();
        }