Improve streams quality settings

This commit is contained in:
Arkadiusz Fal
2022-03-27 20:59:22 +02:00
parent 83db550c18
commit 61054862d2
6 changed files with 34 additions and 14 deletions

View File

@@ -60,7 +60,7 @@ final class AVPlayerBackend: PlayerBackend {
addPlayerTimeControlStatusObserver()
}
func bestPlayable(_ streams: [Stream]) -> Stream? {
func bestPlayable(_ streams: [Stream], maxResolution _: ResolutionSetting) -> Stream? {
streams.first { $0.kind == .hls } ??
streams.filter { $0.kind == .adaptive }.max { $0.resolution < $1.resolution } ??
streams.first

View File

@@ -52,8 +52,10 @@ final class MPVBackend: PlayerBackend {
clientTimer.eventHandler = getClientUpdates
}
func bestPlayable(_ streams: [Stream]) -> Stream? {
streams.filter { $0.kind == .adaptive }.max { $0.resolution < $1.resolution } ??
func bestPlayable(_ streams: [Stream], maxResolution: ResolutionSetting) -> Stream? {
streams
.filter { $0.kind == .adaptive && $0.resolution <= maxResolution.value }
.max { $0.resolution < $1.resolution } ??
streams.first { $0.kind == .hls } ??
streams.first
}

View File

@@ -16,7 +16,7 @@ protocol PlayerBackend {
var isPlaying: Bool { get }
var playerItemDuration: CMTime? { get }
func bestPlayable(_ streams: [Stream]) -> Stream?
func bestPlayable(_ streams: [Stream], maxResolution: ResolutionSetting) -> Stream?
func canPlay(_ stream: Stream) -> Bool
func playStream(

View File

@@ -94,13 +94,7 @@ extension PlayerModel {
streams = streams.filter { backend.canPlay($0) }
switch quality {
case .best:
return backend.bestPlayable(streams)
default:
let sorted = streams.filter { $0.kind != .hls }.sorted { $0.resolution > $1.resolution }.sorted { $0.kind < $1.kind }
return sorted.first(where: { $0.resolution.height <= quality.value.height })
}
return backend.bestPlayable(streams, maxResolution: quality)
}
func advanceToNextItem() {