mirror of
https://github.com/jellyfin/jellyfin-web.git
synced 2024-11-17 02:48:19 -07:00
feat: resume secondary track for current session
This commit is contained in:
parent
256084ffb8
commit
348de5ac7f
@ -1488,6 +1488,24 @@ class PlaybackManager {
|
||||
return getPlayerData(player).subtitleStreamIndex;
|
||||
};
|
||||
|
||||
self.getSecondarySubtitleStreamIndex = function (player) {
|
||||
player = player || self._currentPlayer;
|
||||
|
||||
try {
|
||||
if (player && !enableLocalPlaylistManagement(player)) {
|
||||
return player.getSecondarySubtitleStreamIndex();
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(`Failed to get secondary stream index: ${e}`);
|
||||
}
|
||||
|
||||
if (!player) {
|
||||
throw new Error('player cannot be null');
|
||||
}
|
||||
|
||||
return getPlayerData(player).secondarySubtitleStreamIndex;
|
||||
};
|
||||
|
||||
function getDeliveryMethod(subtitleStream) {
|
||||
// This will be null for internal subs for local items
|
||||
if (subtitleStream.DeliveryMethod) {
|
||||
|
@ -186,6 +186,10 @@ function tryRemoveElement(elem) {
|
||||
* @type {number | undefined}
|
||||
*/
|
||||
#subtitleTrackIndexToSetOnPlaying;
|
||||
/**
|
||||
* @type {number | undefined}
|
||||
*/
|
||||
#secondarySubtitleTrackIndexToSetOnPlaying;
|
||||
/**
|
||||
* @type {number | null}
|
||||
*/
|
||||
@ -474,6 +478,15 @@ function tryRemoveElement(elem) {
|
||||
this.#subtitleTrackIndexToSetOnPlaying = -1;
|
||||
}
|
||||
}
|
||||
// Continue using the secondary track that has been set during this watch session
|
||||
const currentSecondaryTrackIndex = playbackManager.getSecondarySubtitleStreamIndex();
|
||||
this.#secondarySubtitleTrackIndexToSetOnPlaying = currentSecondaryTrackIndex == null ? -1 : currentSecondaryTrackIndex;
|
||||
if (this.#secondarySubtitleTrackIndexToSetOnPlaying != null && this.#secondarySubtitleTrackIndexToSetOnPlaying >= 0) {
|
||||
const initialSecondarySubtitleStream = options.mediaSource.MediaStreams[this.#secondarySubtitleTrackIndexToSetOnPlaying];
|
||||
if (!initialSecondarySubtitleStream || initialSecondarySubtitleStream.DeliveryMethod !== 'External') {
|
||||
this.#secondarySubtitleTrackIndexToSetOnPlaying = -1;
|
||||
}
|
||||
}
|
||||
|
||||
this.#audioTrackIndexToSetOnPlaying = options.playMethod === 'Transcode' ? null : options.mediaSource.DefaultAudioStreamIndex;
|
||||
|
||||
@ -889,6 +902,16 @@ function tryRemoveElement(elem) {
|
||||
if (this.#audioTrackIndexToSetOnPlaying != null && this.canSetAudioStreamIndex()) {
|
||||
this.setAudioStreamIndex(this.#audioTrackIndexToSetOnPlaying);
|
||||
}
|
||||
|
||||
if (this.#secondarySubtitleTrackIndexToSetOnPlaying != null && this.#secondarySubtitleTrackIndexToSetOnPlaying >= 0) {
|
||||
/**
|
||||
* Using a 0ms timeout to set the secondary subtitles because of some weird race condition when
|
||||
* setting both primary and secondary tracks at the same time.
|
||||
* The `TextTrack` content and cues will somehow get mixed up and each track will play a mix of both languages.
|
||||
* Putting this in a timeout fixes it completely.
|
||||
*/
|
||||
setTimeout(() => this.setSecondarySubtitleStreamIndex(this.#secondarySubtitleTrackIndexToSetOnPlaying), 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user