fix(mpv): handle audio track selection for transcoded streams on iOS

This commit is contained in:
Fredrik Burmester
2026-01-15 07:53:15 +01:00
parent 51cd195bfe
commit 28b67f3ad6
2 changed files with 17 additions and 2 deletions

View File

@@ -531,7 +531,11 @@ export default function page() {
subtitleIndex, subtitleIndex,
isTranscoding, isTranscoding,
); );
const initialAudioId = getMpvAudioId(mediaSource, audioIndex); const initialAudioId = getMpvAudioId(
mediaSource,
audioIndex,
isTranscoding,
);
// Calculate start position directly here to avoid timing issues // Calculate start position directly here to avoid timing issues
const startTicks = playbackPositionFromUrl const startTicks = playbackPositionFromUrl

View File

@@ -91,21 +91,32 @@ export const getMpvSubtitleId = (
/** /**
* Calculate the MPV track ID for a given Jellyfin audio index. * Calculate the MPV track ID for a given Jellyfin audio index.
* *
* Audio tracks are simpler - they're always in MPV (no burn-in like image subs). * For direct play: Audio tracks map to their position in the file (1-based).
* For transcoding: Only ONE audio track exists in the HLS stream (the selected one),
* so we should return 1 or undefined to use the default track.
*
* MPV track IDs are 1-based. * MPV track IDs are 1-based.
* *
* @param mediaSource - The media source containing audio streams * @param mediaSource - The media source containing audio streams
* @param jellyfinAudioIndex - The Jellyfin server-side audio index * @param jellyfinAudioIndex - The Jellyfin server-side audio index
* @param isTranscoding - Whether the stream is being transcoded
* @returns MPV track ID (1-based), or undefined if not found * @returns MPV track ID (1-based), or undefined if not found
*/ */
export const getMpvAudioId = ( export const getMpvAudioId = (
mediaSource: MediaSourceInfo | null | undefined, mediaSource: MediaSourceInfo | null | undefined,
jellyfinAudioIndex: number | undefined, jellyfinAudioIndex: number | undefined,
isTranscoding: boolean,
): number | undefined => { ): number | undefined => {
if (jellyfinAudioIndex === undefined) { if (jellyfinAudioIndex === undefined) {
return undefined; return undefined;
} }
// When transcoding, Jellyfin only includes the selected audio track in the HLS stream.
// So there's only 1 audio track - no need to specify an ID.
if (isTranscoding) {
return undefined;
}
const allAudio = const allAudio =
mediaSource?.MediaStreams?.filter((s) => s.Type === "Audio") || []; mediaSource?.MediaStreams?.filter((s) => s.Type === "Audio") || [];