From 6978e9437ccb93c154e02d48863ebf9ad1a29842 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toni=20F=C3=B6rster?= Date: Sat, 31 Aug 2024 14:22:28 +0200 Subject: [PATCH] fix crash on HLS live playback MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fixes #774 Signed-off-by: Toni Förster --- Model/Player/Backends/PlayerBackend.swift | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Model/Player/Backends/PlayerBackend.swift b/Model/Player/Backends/PlayerBackend.swift index 9f02cfcb..ecf3bb58 100644 --- a/Model/Player/Backends/PlayerBackend.swift +++ b/Model/Player/Backends/PlayerBackend.swift @@ -153,7 +153,8 @@ extension PlayerBackend { // Filter out non-HLS streams and streams with resolution more than maxResolution let nonHLSStreams = streams.filter { let isHLS = $0.kind == .hls - let isWithinResolution = $0.resolution <= maxResolution.value + // Safely unwrap resolution and maxResolution.value to avoid crashes + let isWithinResolution = ($0.resolution != nil && maxResolution.value != nil) ? $0.resolution! <= maxResolution.value! : false logger.info("Stream ID: \($0.id) - Kind: \(String(describing: $0.kind)) - Resolution: \(String(describing: $0.resolution)) - Bitrate: \($0.bitrate ?? 0)") logger.info("Is HLS: \(isHLS), Is within resolution: \(isWithinResolution)") return !isHLS && isWithinResolution @@ -187,7 +188,8 @@ extension PlayerBackend { } let filteredStreams = adjustedStreams.filter { stream in - let isWithinResolution = stream.resolution <= maxResolution.value + // Safely unwrap resolution and maxResolution.value to avoid crashes + let isWithinResolution = (stream.resolution != nil && maxResolution.value != nil) ? stream.resolution! <= maxResolution.value! : false logger.info("Filtered stream ID: \(stream.id) - Is within max resolution: \(isWithinResolution)") return isWithinResolution }