From 6c3b6317dcbfcf184459cb752c0bc91432ddda58 Mon Sep 17 00:00:00 2001 From: BakerAO Date: Thu, 26 Sep 2024 14:23:41 -0500 Subject: [PATCH 1/4] Keybind C to auto select subtitle track --- src/controllers/playback/video/index.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/controllers/playback/video/index.js b/src/controllers/playback/video/index.js index b6439216ce7..59a1f5fe41f 100644 --- a/src/controllers/playback/video/index.js +++ b/src/controllers/playback/video/index.js @@ -1176,6 +1176,21 @@ export default function (view) { } } + function autoSelectSubtitleTrack() { + const player = currentPlayer; + const streams = playbackManager.subtitleTracks(player); + const currentIndex = playbackManager.getSubtitleStreamIndex(player) ?? -1; + + if (currentIndex === -1 && streams.length > 0) { + const firstSubtitleIndex = streams[0].Index; + playbackManager.setSubtitleStreamIndex(firstSubtitleIndex, player); + } else { + playbackManager.setSubtitleStreamIndex(-1, player); + } + + toggleSubtitleSync(); + } + /** * Clicked element. * To skip 'click' handling on Firefox/Edge. @@ -1387,6 +1402,13 @@ export default function (view) { playbackManager.previousChapter(currentPlayer); } break; + case 'c': + case 'C': + if (!e.shiftKey) { + e.preventDefault(); + autoSelectSubtitleTrack(); + } + break; case 'g': case 'G': if (!e.shiftKey) { From 7c30c2e860559d9734bc72ff056741b681239467 Mon Sep 17 00:00:00 2001 From: BakerAO Date: Mon, 30 Sep 2024 11:03:55 -0500 Subject: [PATCH 2/4] Use default subtitle index if set --- src/controllers/playback/video/index.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/controllers/playback/video/index.js b/src/controllers/playback/video/index.js index 59a1f5fe41f..88a8376fc3e 100644 --- a/src/controllers/playback/video/index.js +++ b/src/controllers/playback/video/index.js @@ -1178,17 +1178,20 @@ export default function (view) { function autoSelectSubtitleTrack() { const player = currentPlayer; - const streams = playbackManager.subtitleTracks(player); + const streams = playbackManager.subtitleTracks(player) ?? []; const currentIndex = playbackManager.getSubtitleStreamIndex(player) ?? -1; + const defaultIndex = player?.streamInfo?.mediaSource?.DefaultSubtitleStreamIndex ?? -1; if (currentIndex === -1 && streams.length > 0) { - const firstSubtitleIndex = streams[0].Index; - playbackManager.setSubtitleStreamIndex(firstSubtitleIndex, player); + if (defaultIndex > -1) { + playbackManager.setSubtitleStreamIndex(defaultIndex, player); + } else { + const firstSubtitleIndex = streams[0].Index; + playbackManager.setSubtitleStreamIndex(firstSubtitleIndex, player); + } } else { playbackManager.setSubtitleStreamIndex(-1, player); } - - toggleSubtitleSync(); } /** From 3f60e7df4c661b72c04704de2dd7f927c29718a0 Mon Sep 17 00:00:00 2001 From: Baker Ousley Date: Mon, 30 Sep 2024 12:34:01 -0500 Subject: [PATCH 3/4] Update src/controllers/playback/video/index.js Co-authored-by: viown <48097677+viown@users.noreply.github.com> --- src/controllers/playback/video/index.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/controllers/playback/video/index.js b/src/controllers/playback/video/index.js index 88a8376fc3e..9249eaf7aad 100644 --- a/src/controllers/playback/video/index.js +++ b/src/controllers/playback/video/index.js @@ -1183,12 +1183,8 @@ export default function (view) { const defaultIndex = player?.streamInfo?.mediaSource?.DefaultSubtitleStreamIndex ?? -1; if (currentIndex === -1 && streams.length > 0) { - if (defaultIndex > -1) { - playbackManager.setSubtitleStreamIndex(defaultIndex, player); - } else { - const firstSubtitleIndex = streams[0].Index; - playbackManager.setSubtitleStreamIndex(firstSubtitleIndex, player); - } + const subtitleIndex = defaultIndex != -1 ? defaultIndex : streams[0].Index; + playbackManager.setSubtitleStreamIndex(subtitleIndex, player); } else { playbackManager.setSubtitleStreamIndex(-1, player); } From 788ddaa6d85a80ce88843f0ac781e765b9a535ee Mon Sep 17 00:00:00 2001 From: Baker Ousley Date: Mon, 30 Sep 2024 14:33:55 -0500 Subject: [PATCH 4/4] Update src/controllers/playback/video/index.js Co-authored-by: viown <48097677+viown@users.noreply.github.com> --- src/controllers/playback/video/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controllers/playback/video/index.js b/src/controllers/playback/video/index.js index 9249eaf7aad..d4425b77365 100644 --- a/src/controllers/playback/video/index.js +++ b/src/controllers/playback/video/index.js @@ -1178,7 +1178,7 @@ export default function (view) { function autoSelectSubtitleTrack() { const player = currentPlayer; - const streams = playbackManager.subtitleTracks(player) ?? []; + const streams = playbackManager.subtitleTracks(player); const currentIndex = playbackManager.getSubtitleStreamIndex(player) ?? -1; const defaultIndex = player?.streamInfo?.mediaSource?.DefaultSubtitleStreamIndex ?? -1;