Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keybind C to auto select subtitle track #6121

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
25 changes: 25 additions & 0 deletions src/controllers/playback/video/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1176,6 +1176,24 @@ export default function (view) {
}
}

function autoSelectSubtitleTrack() {
const player = currentPlayer;
const streams = playbackManager.subtitleTracks(player) ?? [];
BakerAO marked this conversation as resolved.
Show resolved Hide resolved
const currentIndex = playbackManager.getSubtitleStreamIndex(player) ?? -1;
BakerAO marked this conversation as resolved.
Show resolved Hide resolved
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);
}
BakerAO marked this conversation as resolved.
Show resolved Hide resolved
} else {
playbackManager.setSubtitleStreamIndex(-1, player);
}
}

/**
* Clicked element.
* To skip 'click' handling on Firefox/Edge.
Expand Down Expand Up @@ -1387,6 +1405,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) {
Expand Down
Loading