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); } }
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; } }
public void RunMainLoop() { ConsoleKeyInfo choice; PrintUI(); do { while (!Console.KeyAvailable) { if (needUIUpdate) { PrintUI(); needUIUpdate = false; } PrintSongPosition(); Thread.Sleep(100); } try { choice = Console.ReadKey(true); switch (char.ToLower(choice.KeyChar)) { case 'x': case 'q': return; case ' ': if (player.IsPlaying()) { player.Stop(); } else { player.Play(); } break; case 'n': PlayNext(true); break; case 's': PandoraStation newStation = ShowStationChooser(); if (newStation != null && newStation != musicBox.CurrentStation) { ShowWaitIcon(true); musicBox.CurrentStation = newStation; Settings.Default.LastStationId = musicBox.CurrentStation.Id; Settings.Default.Save(); PlayNext(false); ShowWaitIcon(false); } break; case '?': case 'h': showHelp = !showHelp; modalWindowDisplayed = showHelp; needUIUpdate = true; break; case '+': musicBox.RateSong(musicBox.CurrentSong, PandoraRating.Love); needUIUpdate = true; break; case '-': musicBox.RateSong(musicBox.CurrentSong, PandoraRating.Hate); PlayNext(true); break; case 'b': musicBox.TemporarilyBanSong(musicBox.CurrentSong); PlayNext(true); break; case 'p': PrintText(" ", 0, 7); Settings.Default.DisplayPosition = !Settings.Default.DisplayPosition; Settings.Default.Save(); break; } if (choice.Key == ConsoleKey.Escape) { if (showHelp) { showHelp = false; modalWindowDisplayed = false; needUIUpdate = true; } else { return; } } if (choice.Key == ConsoleKey.UpArrow) { player.Volume += 0.01; PrintVolume(); Settings.Default.Volume = player.Volume; Settings.Default.Save(); } if (choice.Key == ConsoleKey.DownArrow) { player.Volume -= 0.01; PrintVolume(); Settings.Default.Volume = player.Volume; Settings.Default.Save(); } if (choice.Key == ConsoleKey.RightArrow) { PlayNext(true); } } catch (PandoraException e) { PrintText(e.ErrorCode + ": " + e.Message, 0, Console.WindowHeight - 5, ConsoleColor.Red); } } while (true); }