From 256bbd52a704298cb02035657b1262e7b584031c Mon Sep 17 00:00:00 2001 From: Arkadiusz Fal Date: Mon, 22 Aug 2022 19:03:49 +0200 Subject: [PATCH] Extend available streams formats list to AVPlayer --- Model/Player/Backends/AVPlayerBackend.swift | 13 +++++++++---- Model/Stream.swift | 2 +- Shared/Settings/QualityProfileForm.swift | 4 ++-- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/Model/Player/Backends/AVPlayerBackend.swift b/Model/Player/Backends/AVPlayerBackend.swift index 4ae6fb78..5cd52047 100644 --- a/Model/Player/Backends/AVPlayerBackend.swift +++ b/Model/Player/Backends/AVPlayerBackend.swift @@ -83,13 +83,18 @@ final class AVPlayerBackend: PlayerBackend { playerLayer.player = avPlayer } - func bestPlayable(_ streams: [Stream], maxResolution _: ResolutionSetting) -> Stream? { - streams.first { $0.kind == .hls } ?? - streams.max { $0.resolution < $1.resolution } + func bestPlayable(_ streams: [Stream], maxResolution: ResolutionSetting) -> Stream? { + let sortedByResolution = streams + .filter { ($0.kind == .adaptive || $0.kind == .stream) && $0.resolution <= maxResolution.value } + .sorted { $0.resolution > $1.resolution } + + return streams.first { $0.kind == .hls } ?? + sortedByResolution.first { $0.kind == .stream } ?? + sortedByResolution.first } func canPlay(_ stream: Stream) -> Bool { - stream.kind == .hls || (stream.kind == .stream && stream.resolution.height <= 720) + stream.kind == .hls || stream.kind == .stream || (stream.kind == .adaptive && stream.format == .mp4) } func playStream( diff --git a/Model/Stream.swift b/Model/Stream.swift index 2f08c78f..1cc97449 100644 --- a/Model/Stream.swift +++ b/Model/Stream.swift @@ -59,7 +59,7 @@ class Stream: Equatable, Hashable, Identifiable { } static func < (lhs: Resolution, rhs: Resolution) -> Bool { - lhs.height < rhs.height + lhs.height == rhs.height ? (lhs.refreshRate < rhs.refreshRate) : (lhs.height < rhs.height) } } diff --git a/Shared/Settings/QualityProfileForm.swift b/Shared/Settings/QualityProfileForm.swift index d4224307..9c6e80ef 100644 --- a/Shared/Settings/QualityProfileForm.swift +++ b/Shared/Settings/QualityProfileForm.swift @@ -268,7 +268,7 @@ struct QualityProfileForm: View { func isFormatDisabled(_ format: QualityProfile.Format) -> Bool { guard backend == .appleAVPlayer else { return false } - let avPlayerFormats = [QualityProfile.Format.hls, .stream] + let avPlayerFormats = [QualityProfile.Format.hls, .stream, .mp4] return !avPlayerFormats.contains(format) } @@ -276,7 +276,7 @@ struct QualityProfileForm: View { func isResolutionDisabled(_ resolution: ResolutionSetting) -> Bool { guard backend == .appleAVPlayer else { return false } - return resolution.value.height > 720 + return resolution.value > .hd720p30 } func initializeForm() {