From e1b9730e9bd1bb1d5131ef6de5a3c5a08a56eeca Mon Sep 17 00:00:00 2001 From: stax76 Date: Tue, 12 Jul 2022 05:49:05 +0200 Subject: [PATCH] use mpv.net to cycle subtitles --- src/Misc/Commands.cs | 34 +++++++++++++++++++++++++++++++++- src/Resources/input.conf.txt | 2 +- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/Misc/Commands.cs b/src/Misc/Commands.cs index c8f9ad0..9d64b41 100644 --- a/src/Misc/Commands.cs +++ b/src/Misc/Commands.cs @@ -25,6 +25,7 @@ namespace mpvnet switch (id) { case "cycle-audio": CycleAudio(); break; + case "cycle-subtitles": CycleSubtitles(); break; case "load-audio": LoadAudio(); break; case "load-sub": LoadSubtitle(); break; case "open-clipboard": OpenFromClipboard(); break; @@ -309,13 +310,44 @@ namespace mpvnet if (++aid > tracks.Length) aid = 1; - Core.CommandV("set", "aid", aid.ToString()); + Core.SetPropertyInt("aid", aid); } Core.CommandV("show-text", aid + "/" + tracks.Length + ": " + tracks[aid - 1].Text.Substring(3), "5000"); } } + public static void CycleSubtitles() + { + Core.UpdateExternalTracks(); + + lock (Core.MediaTracksLock) + { + MediaTrack[] tracks = Core.MediaTracks.Where(track => track.Type == "s").ToArray(); + + if (tracks.Length < 1) + { + Core.CommandV("show-text", "No subtitles"); + return; + } + + int sid = Core.GetPropertyInt("sid"); + + if (tracks.Length > 1) + { + if (++sid > tracks.Length) + sid = 0; + + Core.SetPropertyInt("sid", sid); + } + + if (sid == 0) + Core.CommandV("show-text", "No subtitle"); + else + Core.CommandV("show-text", sid + "/" + tracks.Length + ": " + tracks[sid - 1].Text.Substring(3), "5000"); + } + } + public static void ShowCommands() { string jsonString = Core.GetPropertyString("command-list"); diff --git a/src/Resources/input.conf.txt b/src/Resources/input.conf.txt index 7e25e05..08f5b85 100644 --- a/src/Resources/input.conf.txt +++ b/src/Resources/input.conf.txt @@ -80,7 +80,7 @@ _ ignore #menu: Audio > - Ctrl+d add audio-delay 0.1 #menu: Audio > Delay +0.1 Ctrl+D add audio-delay -0.1 #menu: Audio > Delay -0.1 -KP8 cycle sub #menu: Subtitle > Cycle/Next +KP8 script-message-to mpvnet cycle-subtitles #menu: Subtitle > Cycle/Next #menu: Subtitle > Cycle/Next v cycle sub-visibility #menu: Subtitle > Toggle Visibility _ ignore #menu: Subtitle > - z add sub-delay -0.1 #menu: Subtitle > Delay -0.1