Add optional AVPlayer support for non-streamable MP4/AVC1 formats

AVPlayer has a fundamental limitation with MP4/AVC1 progressive downloads where the moov atom position affects playback start time. When moov is at the end of the file, AVPlayer must download the entire file before starting playback. MPV doesn't have this limitation.

This commit adds an advanced setting to optionally enable these formats in AVPlayer with appropriate warnings:

- Added new setting: "Enable non-streamable formats (MP4/AVC1)"
- Default: disabled (formats hidden, MPV handles them)
- When enabled: MP4/AVC1 formats up to 1080p appear in AVPlayer quality selector
- Resolution limit: 1080p maximum (higher resolutions can't be played properly)
- Clear warning about slow loading and 1080p limitation
- Automatic stream refresh when setting is toggled
- Full import/export support for the setting
This commit is contained in:
Arkadiusz Fal
2025-11-23 13:30:46 +01:00
parent 41a33634ee
commit e6e69eb757
6 changed files with 61 additions and 6 deletions

View File

@@ -16,10 +16,12 @@ struct AdvancedSettings: View {
@Default(.feedCacheSize) private var feedCacheSize
@Default(.showPlayNowInBackendContextMenu) private var showPlayNowInBackendContextMenu
@Default(.videoLoadingRetryCount) private var videoLoadingRetryCount
@Default(.avPlayerAllowsNonStreamableFormats) private var avPlayerAllowsNonStreamableFormats
@State private var filesToShare = [MPVClient.logFile]
@State private var presentingShareSheet = false
@ObservedObject private var player = PlayerModel.shared
private var settings = SettingsModel.shared
var body: some View {
@@ -73,6 +75,10 @@ struct AdvancedSettings: View {
videoLoadingRetryCountField
}
Section(header: SettingsHeader(text: "AVPlayer"), footer: avPlayerNonStreamableFormatsFooter) {
avPlayerAllowsNonStreamableFormatsToggle
}
Section(header: SettingsHeader(text: "MPV"), footer: mpvFooter) {
showMPVPlaybackStatsToggle
#if !os(tvOS)
@@ -370,6 +376,22 @@ struct AdvancedSettings: View {
Text(String(format: "Total size: %@".localized(), BaseCacheModel.shared.totalSizeFormatted))
.foregroundColor(.secondary)
}
var avPlayerAllowsNonStreamableFormatsToggle: some View {
Toggle("Enable non-streamable formats (MP4/AVC1)", isOn: $avPlayerAllowsNonStreamableFormats)
.onChange(of: avPlayerAllowsNonStreamableFormats) { _ in
// Trigger refresh of available streams when setting changes
if let video = player.currentVideo {
player.loadAvailableStreams(video)
}
}
}
@ViewBuilder var avPlayerNonStreamableFormatsFooter: some View {
Text("Non-streamable video formats (MP4/AVC1) may take a long time to start playback with AVPlayer. These formats require downloading metadata before playback can begin. Limited to 1080p maximum. For better performance with these formats, use MPV backend instead.")
.foregroundColor(.secondary)
.fixedSize(horizontal: false, vertical: true)
}
}
struct AdvancedSettings_Previews: PreviewProvider {