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

added shortkey to toggle caption. UX improvement. #675

Open
wants to merge 3 commits into
base: development
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/routes/Player/Player.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ const Player = ({ urlParams, queryParams }) => {
const defaultSubtitlesSelected = React.useRef(false);
const defaultAudioTrackSelected = React.useRef(false);
const [error, setError] = React.useState(null);
const [previousSubtitlesTrackId, setPreviousSubtitlesTrackId] = React.useState(null);


const onImplementationChanged = React.useCallback(() => {
video.setProp('subtitlesSize', settings.subtitlesSize);
Expand Down Expand Up @@ -183,6 +185,12 @@ const Player = ({ urlParams, queryParams }) => {
video.setProp('extraSubtitlesDelay', delay);
}, []);

const onSubtitlesTrackSelected = React.useCallback((id) => {
video.setProp('selectedSubtitlesTrackId', id);
video.setProp('selectedExtraSubtitlesTrackId', null);
setPreviousSubtitlesTrackId(id);
}, []);

const onSubtitlesSizeChanged = React.useCallback((size) => {
updateSettings({ subtitlesSize: size });
}, [updateSettings]);
Expand Down Expand Up @@ -515,6 +523,20 @@ const Player = ({ urlParams, queryParams }) => {

break;
}
case 'KeyC': {
if (!menusOpen && !nextVideoPopupOpen) {
if (video.state.selectedSubtitlesTrackId !== null) {
onSubtitlesTrackSelected(null);
} else if (previousSubtitlesTrackId !== null) {
onSubtitlesTrackSelected(previousSubtitlesTrackId);
} else if (video.state.subtitlesTracks.length > 0) {
onSubtitlesTrackSelected(video.state.subtitlesTracks[0].id);
} else if (video.state.extraSubtitlesTracks.length > 0) {
onExtraSubtitlesTrackSelected(video.state.extraSubtitlesTracks[0].id);
}
}
break;
}
case 'KeyI': {
closeMenus();
if (player.metaItem !== null && player.metaItem.type === 'Ready') {
Expand Down