From fba01e35a341dd775e8e931634b86ba8655c88c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toni=20F=C3=B6rster?= Date: Sat, 11 May 2024 14:08:40 +0200 Subject: [PATCH] apply best resolution from non HLS to HLS stream This makes sure that HLS Streams can be compared with non HLS streams, otherwise HLS would have been the first selected since the maxResolution.value might have been higher then what could actually be the highest resolution served. --- Model/Player/Backends/PlayerBackend.swift | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Model/Player/Backends/PlayerBackend.swift b/Model/Player/Backends/PlayerBackend.swift index 88890ffb..fce56900 100644 --- a/Model/Player/Backends/PlayerBackend.swift +++ b/Model/Player/Backends/PlayerBackend.swift @@ -131,9 +131,17 @@ extension PlayerBackend { } func bestPlayable(_ streams: [Stream], maxResolution: ResolutionSetting, formatOrder: [QualityProfile.Format]) -> Stream? { + // filter out non HLS streams + let nonHLSStreams = streams.filter { $0.kind != .hls } + + // find max resolution from non HLS streams + let bestResolution = nonHLSStreams + .filter { $0.resolution <= maxResolution.value } + .max { $0.resolution < $1.resolution }?.resolution + return streams.map { stream in if stream.kind == .hls { - stream.resolution = maxResolution.value + stream.resolution = bestResolution ?? maxResolution.value stream.format = .hls } else if stream.kind == .stream { stream.format = .stream