mirror of
https://github.com/yattee/yattee.git
synced 2025-11-24 02:08:17 +00:00
Prefer fast-loading formats when switching to AVPlayer
When switching from MPV to AVPlayer, prioritize HLS and stream formats over non-streamable MP4/AVC1 formats to avoid long loading times. Changes: - Added isFastLoadingFormat() helper to AVPlayerBackend - Modified streamByQualityProfile to prefer fast-loading formats for AVPlayer - Falls back to non-streamable formats only if no fast-loading option exists - Ensures quick backend switching without waiting for metadata download
This commit is contained in:
@@ -178,6 +178,12 @@ final class AVPlayerBackend: PlayerBackend {
|
||||
return stream.kind == .hls || stream.kind == .stream
|
||||
}
|
||||
|
||||
func isFastLoadingFormat(_ stream: Stream) -> Bool {
|
||||
// HLS and stream formats load quickly
|
||||
// Non-streamable MP4/AVC1 formats may take a long time
|
||||
return stream.kind == .hls || stream.kind == .stream
|
||||
}
|
||||
|
||||
func playStream(
|
||||
_ stream: Stream,
|
||||
of video: Video,
|
||||
|
||||
@@ -133,6 +133,26 @@ extension PlayerModel {
|
||||
|
||||
let profile = qualityProfile ?? .defaultProfile
|
||||
|
||||
// For AVPlayer, prefer fast-loading formats (HLS/stream) over non-streamable formats
|
||||
// to avoid long loading times when switching backends
|
||||
if activeBackend == .appleAVPlayer, let avBackend = backend as? AVPlayerBackend {
|
||||
// Try to find a fast-loading stream first
|
||||
let fastLoadingStreams = availableStreams.filter { backend.canPlay($0) && avBackend.isFastLoadingFormat($0) }
|
||||
if let fastStream = backend.bestPlayable(
|
||||
fastLoadingStreams.filter { profile.isPreferred($0) },
|
||||
maxResolution: profile.resolution, formatOrder: profile.formats
|
||||
) {
|
||||
return fastStream
|
||||
}
|
||||
// Fallback to any fast-loading stream
|
||||
if let fastStream = backend.bestPlayable(
|
||||
fastLoadingStreams,
|
||||
maxResolution: profile.resolution, formatOrder: profile.formats
|
||||
) {
|
||||
return fastStream
|
||||
}
|
||||
}
|
||||
|
||||
// First attempt: Filter by both `canPlay` and `isPreferred`
|
||||
if let streamPreferredForProfile = backend.bestPlayable(
|
||||
availableStreams.filter { backend.canPlay($0) && profile.isPreferred($0) },
|
||||
|
||||
Reference in New Issue
Block a user