public async Task Play(PlayOptions options) { CurrentPlaylistIndex = 0; CurrentPlayOptions = options; _playlist = options.Items.ToList(); _currentPlaybackDispatcher = _presentation.Window.Dispatcher; try { _currentPlaybackDispatcher.Invoke(() => { _hiddenWindow.WindowsFormsHost.Child = _mediaPlayer = new DirectShowPlayer(_logger, _hiddenWindow, this) { BackColor = Color.Black, BorderStyle = BorderStyle.None }; //HideCursor(); }); await PlayTrack(0, options.StartPositionTicks); } catch (Exception ex) { _logger.ErrorException("Error beginning playback", ex); DisposePlayer(); throw; } }
private async Task PlayTrack(int index, long?startPositionTicks) { var previousMedia = CurrentMedia; var previousIndex = CurrentPlaylistIndex; var endingTicks = CurrentPositionTicks; var options = CurrentPlayOptions; var playableItem = await GetPlayableItem(options.Items[index], startPositionTicks, CancellationToken.None); try { var enableMadVr = EnableMadvr(options); //var enableReclock = EnableReclock(options); InvokeOnPlayerThread(() => { //create a fresh DS Player everytime we want one DisposePlayer(); _mediaPlayer = new DirectShowPlayer(_logger, _hiddenWindow, this, _presentation.WindowHandle, _sessionManager, _config, _inputManager, _apiClient, _zipClient, _httpClient); _mediaPlayer.Play(playableItem, enableMadVr, false); }, true); } catch { OnPlaybackStopped(playableItem, null, TrackCompletionReason.Failure, null); throw; } CurrentPlaylistIndex = index; if (startPositionTicks.HasValue && startPositionTicks.Value > 0) { InvokeOnPlayerThread(() => _mediaPlayer.Seek(startPositionTicks.Value)); } if (previousMedia != null && MediaChanged != null) { var args = new MediaChangeEventArgs { Player = this, NewPlaylistIndex = index, NewMedia = CurrentMedia, PreviousMedia = previousMedia, PreviousPlaylistIndex = previousIndex, EndingPositionTicks = endingTicks }; _presentation.Window.Dispatcher.Invoke ( () => MediaChanged(this, args) ); } }
/// <summary> /// Enables the madvr. /// </summary> /// <param name="options">The options.</param> /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns> //private bool EnableReclock(PlayOptions options) //{ // var video = options.Items.First(); // if (!video.IsVideo) // { // return false; // } // if (!_config.Configuration.InternalPlayerConfiguration.EnableReclock) // { // return false; // } // if (!options.GoFullScreen) // { // return false; // } // return true; //} private void DisposePlayer() { if (_mediaPlayer != null) { InvokeOnPlayerThread(() => { _mediaPlayer.Dispose(); _mediaPlayer = null; //force the object to get cleaned up }); } }
private async Task PlayTrack(int index, long? startPositionTicks) { var previousMedia = CurrentMedia; var previousIndex = CurrentPlaylistIndex; var endingTicks = CurrentPositionTicks; var options = CurrentPlayOptions; var playableItem = await GetPlayableItem(options.Items[index], startPositionTicks, CancellationToken.None); try { var enableMadVr = EnableMadvr(options); //var enableReclock = EnableReclock(options); InvokeOnPlayerThread(() => { //create a fresh DS Player everytime we want one DisposePlayer(); _mediaPlayer = new DirectShowPlayer(_logger, _hiddenWindow, this, _presentation.WindowHandle, _sessionManager, _config, _inputManager, _apiClient, _zipClient, _httpClient); _mediaPlayer.Play(playableItem, enableMadVr, false); }); } catch { DisposeMount(playableItem); throw; } CurrentPlaylistIndex = index; if (startPositionTicks.HasValue && startPositionTicks.Value > 0) { InvokeOnPlayerThread(() => _mediaPlayer.Seek(startPositionTicks.Value)); } if (previousMedia != null && MediaChanged != null) { var args = new MediaChangeEventArgs { Player = this, NewPlaylistIndex = index, NewMedia = CurrentMedia, PreviousMedia = previousMedia, PreviousPlaylistIndex = previousIndex, EndingPositionTicks = endingTicks }; _presentation.Window.Dispatcher.Invoke ( () => MediaChanged(this, args) ); } }
public async Task Play(PlayOptions options) { CurrentPlaylistIndex = 0; CurrentPlayOptions = options; _playlist = options.Items.ToList(); try { await InvokeOnPlayerThreadAsync(() => { _mediaPlayer = new DirectShowPlayer(_logger, _windowManager, this, _presentation.MainApplicationWindowHandle, _sessionManager, _config/*, _inputManager*/); //HideCursor(); }); await PlayTrack(0, options.StartPositionTicks); } catch (Exception ex) { _logger.ErrorException("Error beginning playback", ex); DisposePlayer(); throw; } }
private async Task PlayTrack(int index, long? startPositionTicks, StreamInfo previousStreamInfo) { var previousMedia = CurrentMedia; var previousIndex = CurrentPlaylistIndex; var endingTicks = CurrentPositionTicks; var options = CurrentPlayOptions; PlayableItem playableItem; try { playableItem = await GetPlayableItem(options.Items[index], startPositionTicks, CancellationToken.None); } catch (PlaybackException ex) { string text; switch (ex.ErrorCode) { case PlaybackErrorCode.NoCompatibleStream: text = "No compatible streams are currently available. Please try again later or contact your system administrator for details."; break; case PlaybackErrorCode.NotAllowed: text = "You do not have access to play this content at this time. Please contact your system administrator for details."; break; case PlaybackErrorCode.RateLimitExceeded: text = "Your playback limit has been exceeded. Please try again later or contact your system administrator for details."; break; default: text = "There was an error processing the request."; break; } _presentation.ShowMessage(new MessageBoxInfo { Button = MessageBoxButton.OK, Icon = MessageBoxIcon.Error, Caption = "Error", Text = text }); return; } try { var enableMadVr = EnableMadvr(options); //var enableReclock = EnableReclock(options); InvokeOnPlayerThread(() => { //create a fresh DS Player everytime we want one DisposePlayer(); var apiClient = _connectionManager.GetApiClient(playableItem.OriginalItem); _mediaPlayer = new DirectShowPlayer(_logger, _hiddenWindow, this, _presentation.WindowHandle, _sessionManager, _config, _inputManager, apiClient, _zipClient, _httpClient); _mediaPlayer.Play(playableItem, enableMadVr, false); }, true); } catch (PlaybackException ex) { string text; switch (ex.ErrorCode) { case PlaybackErrorCode.NoCompatibleStream: text = "No compatible streams are currently available. Please try again later or contact your system administrator for details."; break; case PlaybackErrorCode.NotAllowed: text = "You do not have access to play this content at this time. Please contact your system administrator for details."; break; case PlaybackErrorCode.RateLimitExceeded: text = "Your playback limit has been exceeded. Please try again later or contact your system administrator for details."; break; default: text = "There was an error processing the request."; break; } _presentation.ShowMessage(new MessageBoxInfo { Button = MessageBoxButton.OK, Icon = MessageBoxIcon.Error, Caption = "Error", Text = text }); OnPlaybackStopped(playableItem, null, TrackCompletionReason.Failure, null); throw; } catch { OnPlaybackStopped(playableItem, null, TrackCompletionReason.Failure, null); throw; } CurrentStreamInfo = playableItem.StreamInfo; CurrentPlaylistIndex = index; if (startPositionTicks.HasValue && startPositionTicks.Value > 0) { InvokeOnPlayerThread(() => _mediaPlayer.Seek(startPositionTicks.Value)); } 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); } if (previousMedia != null && MediaChanged != null) { var args = new MediaChangeEventArgs { Player = this, NewPlaylistIndex = index, NewMedia = CurrentMedia, PreviousMedia = previousMedia, PreviousPlaylistIndex = previousIndex, EndingPositionTicks = endingTicks, PreviousStreamInfo = previousStreamInfo }; _presentation.Window.Dispatcher.Invoke ( () => MediaChanged(this, args) ); } }
private async Task PlayTrack(int index, long? startPositionTicks) { var previousMedia = CurrentMedia; var previousIndex = CurrentPlaylistIndex; var endingTicks = CurrentPositionTicks; var options = CurrentPlayOptions; var playableItem = await GetPlayableItem(options.Items[index], startPositionTicks, CancellationToken.None); try { var enableMadVr = EnableMadvr(options); //var enableReclock = EnableReclock(options); InvokeOnPlayerThread(() => { //create a fresh DS Player everytime we want one DisposePlayer(); var apiClient = _connectionManager.GetApiClient(playableItem.OriginalItem); _mediaPlayer = new DirectShowPlayer(_logger, _hiddenWindow, this, _presentation.WindowHandle, _sessionManager, _config, _inputManager, apiClient, _zipClient, _httpClient); _mediaPlayer.Play(playableItem, enableMadVr, false); }, true); } catch { OnPlaybackStopped(playableItem, null, TrackCompletionReason.Failure, null); throw; } CurrentPlaylistIndex = index; if (startPositionTicks.HasValue && startPositionTicks.Value > 0) { InvokeOnPlayerThread(() => _mediaPlayer.Seek(startPositionTicks.Value)); } 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); } if (previousMedia != null && MediaChanged != null) { var args = new MediaChangeEventArgs { Player = this, NewPlaylistIndex = index, NewMedia = CurrentMedia, PreviousMedia = previousMedia, PreviousPlaylistIndex = previousIndex, EndingPositionTicks = endingTicks }; _presentation.Window.Dispatcher.Invoke ( () => MediaChanged(this, args) ); } }