mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
feat: add native secondary subtitle support
This commit is contained in:
parent
d69d4b22d9
commit
145aea184f
4 changed files with 192 additions and 20 deletions
|
@ -988,9 +988,57 @@ import { setBackdropTransparency, TRANSPARENCY_LEVEL } from '../../../components
|
|||
});
|
||||
}
|
||||
|
||||
function showSecondarySubtitlesMenu(actionsheet, positionTo) {
|
||||
const player = currentPlayer;
|
||||
if (!playbackManager.hasSecondarySubtitleSupport(player)) return;
|
||||
let currentIndex = playbackManager.getSecondarySubtitleStreamIndex(player);
|
||||
const streams = playbackManager.secondarySubtitleTracks(player);
|
||||
|
||||
if (currentIndex == null) {
|
||||
currentIndex = -1;
|
||||
}
|
||||
|
||||
streams.unshift({
|
||||
Index: -1,
|
||||
DisplayTitle: globalize.translate('Off')
|
||||
});
|
||||
|
||||
const menuItems = streams.map(function (stream) {
|
||||
const opt = {
|
||||
name: stream.DisplayTitle,
|
||||
id: stream.Index
|
||||
};
|
||||
|
||||
if (stream.Index === currentIndex) {
|
||||
opt.selected = true;
|
||||
}
|
||||
|
||||
return opt;
|
||||
});
|
||||
|
||||
actionsheet.show({
|
||||
title: globalize.translate('SecondarySubtitles'),
|
||||
items: menuItems,
|
||||
positionTo
|
||||
}).then(function (id) {
|
||||
if (id) {
|
||||
const index = parseInt(id);
|
||||
if (index !== currentIndex) {
|
||||
playbackManager.setSecondarySubtitleStreamIndex(index, player);
|
||||
}
|
||||
}
|
||||
})
|
||||
.finally(() => {
|
||||
resetIdle();
|
||||
});
|
||||
|
||||
setTimeout(resetIdle, 0);
|
||||
}
|
||||
|
||||
function showSubtitleTrackSelection() {
|
||||
const player = currentPlayer;
|
||||
const streams = playbackManager.subtitleTracks(player);
|
||||
const secondaryStreams = playbackManager.secondarySubtitleTracks(player);
|
||||
let currentIndex = playbackManager.getSubtitleStreamIndex(player);
|
||||
|
||||
if (currentIndex == null) {
|
||||
|
@ -1013,18 +1061,37 @@ import { setBackdropTransparency, TRANSPARENCY_LEVEL } from '../../../components
|
|||
|
||||
return opt;
|
||||
});
|
||||
|
||||
// Only show option if: player has support, has more than 1 subtitle track, has valid secondary tracks, primary subtitle is not off
|
||||
if (playbackManager.hasSecondarySubtitleSupport(player) && streams.length > 1 && secondaryStreams.length > 0 && currentIndex !== -1) {
|
||||
const secondarySubtitleMenuItem = {
|
||||
name: globalize.translate('SecondarySubtitles'),
|
||||
id: 'secondarysubtitle'
|
||||
};
|
||||
menuItems.unshift(secondarySubtitleMenuItem);
|
||||
}
|
||||
|
||||
const positionTo = this;
|
||||
|
||||
import('../../../components/actionSheet/actionSheet').then(({default: actionsheet}) => {
|
||||
actionsheet.show({
|
||||
title: globalize.translate('Subtitles'),
|
||||
items: menuItems,
|
||||
resolveOnClick: true,
|
||||
positionTo: positionTo
|
||||
}).then(function (id) {
|
||||
const index = parseInt(id);
|
||||
if (id === 'secondarysubtitle') {
|
||||
try {
|
||||
showSecondarySubtitlesMenu(actionsheet, positionTo);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
} else {
|
||||
const index = parseInt(id);
|
||||
|
||||
if (index !== currentIndex) {
|
||||
playbackManager.setSubtitleStreamIndex(index, player);
|
||||
if (index !== currentIndex) {
|
||||
playbackManager.setSubtitleStreamIndex(index, player);
|
||||
}
|
||||
}
|
||||
|
||||
toggleSubtitleSync();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue