Apply audio mode to downloaded videos

Downloads bypass stream selection and reach play() as ready-made local
file streams, so audio mode never affected them. Apply the mode at that
choke point instead: swap a local video stream for the separately
downloaded audio track, or play a muxed file with the video track
disabled (vid set per-load in MPVClient, never toggled live). The
transform is bidirectional so stored audio-only queue/history entries
restore full video when the mode is off, and setAudioMode now reloads
downloaded content at the current position in both directions.
This commit is contained in:
Arkadiusz Fal
2026-07-17 09:27:09 +02:00
parent 6514cb426e
commit c2554cee04
4 changed files with 111 additions and 7 deletions

View File

@@ -189,6 +189,38 @@ struct StreamResolution: Codable, Hashable, Sendable, Comparable, CustomStringCo
}
}
// MARK: - Audio-Only Variant
extension Stream {
/// Whether the backend must disable the video track when loading this stream:
/// a muxed file being played as audio-only (see `audioOnlyVariant()`).
var requiresVideoTrackDisabled: Bool {
isAudioOnly && videoCodec != nil
}
/// Creates an audio-only copy of this stream keeping the same URL.
/// Used for muxed local files in audio mode: `videoCodec` stays set so
/// `requiresVideoTrackDisabled` tells the backend to skip the video track.
func audioOnlyVariant() -> Stream {
Stream(
url: url,
resolution: nil,
format: format,
videoCodec: videoCodec,
audioCodec: audioCodec,
bitrate: bitrate,
fileSize: fileSize,
isAudioOnly: true,
isLive: isLive,
mimeType: mimeType,
audioLanguage: audioLanguage,
audioTrackName: audioTrackName,
isOriginalAudio: isOriginalAudio,
httpHeaders: httpHeaders
)
}
}
// MARK: - URL Rewriting
extension Stream {