Exemple #1
0
 private void DisposePlayerInternal()
 {
     if (_mediaPlayer != null)
     {
         _mediaPlayer.Dispose();
         _mediaPlayer = null; //force the object to get cleaned up
     }
 }
Exemple #2
0
 private void DisposePlayer()
 {
     if (_mediaPlayer != null)
     {
         InvokeOnPlayerThread(() =>
         {
             _mediaPlayer.Dispose();
             _mediaPlayer = null; //force the object to get cleaned up
         });
     }
 }
Exemple #3
0
        private void PlayTrack(string path, long startPositionTicks, bool isVideo, BaseItemDto item, MediaSourceInfo mediaSource, string forcedVideoRenderer)
        {
            var playableItem = new PlayableItem
            {
                MediaSource  = mediaSource,
                PlayablePath = path,
                OriginalItem = item
            };

            try
            {
                InvokeOnPlayerThread(() =>
                {
                    //create a fresh DS Player everytime we want one
                    DisposePlayer();

                    _mediaPlayer = new DirectShowPlayer(this, _hostForm, _logger, GetConfiguration(), _httpClient);
                    _mediaPlayer.Play(playableItem, forcedVideoRenderer);

                    try
                    {
                        Standby.PreventSleepAndMonitorOff();
                    }
                    catch
                    {
                    }
                }, true);
            }
            catch
            {
                OnPlaybackStopped(playableItem, null, TrackCompletionReason.Failure, null);

                throw;
            }

            if (startPositionTicks > 0)
            {
                InvokeOnPlayerThread(() => _mediaPlayer.Seek(startPositionTicks));
            }

            if (playableItem.OriginalItem.IsVideo)
            {
                var audioIndex    = playableItem.MediaSource.DefaultAudioStreamIndex;
                var subtitleIndex = playableItem.MediaSource.DefaultSubtitleStreamIndex;

                if (audioIndex.HasValue && audioIndex.Value != -1)
                {
                    SetAudioStreamIndex(audioIndex.Value);
                }
                SetSubtitleStreamIndex(subtitleIndex ?? -1);
            }
        }
Exemple #4
0
        public void Play(string path, long startPositionTicks, bool isVideo, BaseItemDto item, MediaSourceInfo mediaSource, bool enableFullScreen, IntPtr videoWindowHandle, DirectShowPlayerConfiguration config)
        {
            var playableItem = new PlayableItem
            {
                MediaSource  = mediaSource,
                PlayablePath = path,
                OriginalItem = item
            };

            try
            {
                InvokeOnPlayerThread(() =>
                {
                    //create a fresh DS Player everytime we want one
                    DisposePlayerInternal();

                    _mediaPlayer = new DirectShowPlayer(this, _logger, config, _httpClient, videoWindowHandle);
                    _mediaPlayer.Play(playableItem, enableFullScreen);

                    try
                    {
                        Standby.PreventSleepAndMonitorOff();
                    }
                    catch
                    {
                    }

                    try
                    {
                        if (startPositionTicks > 0)
                        {
                            _mediaPlayer.Seek(startPositionTicks);
                        }
                    }
                    catch
                    {
                    }

                    if (playableItem.IsVideo)
                    {
                        var audioIndex    = playableItem.MediaSource.DefaultAudioStreamIndex;
                        var subtitleIndex = playableItem.MediaSource.DefaultSubtitleStreamIndex;

                        if (audioIndex.HasValue && audioIndex.Value != -1)
                        {
                            try
                            {
                                SetAudioStreamIndexInternal(audioIndex.Value);
                            }
                            catch
                            {
                            }
                        }
                        try
                        {
                            SetSubtitleStreamIndexInternal(subtitleIndex ?? -1);
                        }
                        catch
                        {
                        }
                    }
                }, true);
            }
            catch (Exception ex)
            {
                OnPlaybackStopped(playableItem, null, TrackCompletionReason.Failure, null);

                throw;
            }
        }