From 297b4fe6ebd6ae6499a7e9c210996749ade00213 Mon Sep 17 00:00:00 2001 From: EffakT Date: Tue, 10 Dec 2024 19:39:40 +1300 Subject: [PATCH] refactor: Update subtitle streams to use TextTrack indexes (#2529) * refactor: Update subtitle streams to use TextTrack indexes, instead of MediaStream indexes * Add comment referring to bug in jellyfin server regarding subtitles --- frontend/src/store/playback-manager.ts | 16 +++++++++------- frontend/src/utils/items.ts | 8 +++++++- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/frontend/src/store/playback-manager.ts b/frontend/src/store/playback-manager.ts index db4605f1d47..b5203599201 100644 --- a/frontend/src/store/playback-manager.ts +++ b/frontend/src/store/playback-manager.ts @@ -270,18 +270,20 @@ class PlaybackManagerStore extends CommonStore { public get currentItemParsedSubtitleTracks(): PlaybackTrack[] | undefined { if (!isNil(this._state.currentMediaSource)) { - return this._state.currentMediaSource.MediaStreams?.map( - (stream, index) => ({ - srcIndex: index, - ...stream - }) - ) - .filter( + // TODO: There is currently a bug in Jellyfin server when adding external subtitles may play the incorrect subtitle + // https://github.com/jellyfin/jellyfin/issues/13198 + return this._state.currentMediaSource.MediaStreams?.filter( sub => sub.Type === MediaStreamType.Subtitle && (sub.DeliveryMethod === SubtitleDeliveryMethod.Encode || sub.DeliveryMethod === SubtitleDeliveryMethod.External) ) + .map( + (stream, index) => ({ + srcIndex: index, + ...stream + }) + ) .map(sub => ({ label: sub.DisplayTitle ?? 'Undefined', src: diff --git a/frontend/src/utils/items.ts b/frontend/src/utils/items.ts index d2cf4557697..e02b5c3e8e0 100644 --- a/frontend/src/utils/items.ts +++ b/frontend/src/utils/items.ts @@ -450,7 +450,13 @@ export function getMediaStreams( mediaStreams: MediaStream[], streamType: string ): MediaStream[] { - return mediaStreams.filter(mediaStream => mediaStream.Type === streamType); + return mediaStreams.filter(mediaStream => mediaStream.Type === streamType) + .map( + (stream, index) => ({ + ...stream, + Index: index + }) + ) } /**