Add nil safety checks for stream resolution handling

Added comprehensive nil checks for stream resolution values across PlayerBackend, QualityProfile, and PlayerQueue to prevent crashes when streams have missing resolution metadata. Also added backend nil checks in PlayerQueue.
This commit is contained in:
Arkadiusz Fal
2025-11-14 18:58:27 +01:00
parent b6df73f949
commit 6511d4c9ba
3 changed files with 40 additions and 9 deletions

View File

@@ -52,7 +52,7 @@ extension PlayerModel {
func playItem(_ item: PlayerQueueItem, at time: CMTime? = nil) {
advancing = false
if !playingInPictureInPicture, !currentItem.isNil {
if !playingInPictureInPicture, !currentItem.isNil, backend != nil {
backend.closeItem()
}
@@ -125,6 +125,12 @@ extension PlayerModel {
}
var streamByQualityProfile: Stream? {
// Safety check: Ensure backend is available
guard backend != nil else {
logger.error("Backend is nil when trying to select stream by quality profile")
return nil
}
let profile = qualityProfile ?? .defaultProfile
// First attempt: Filter by both `canPlay` and `isPreferred`
@@ -229,7 +235,9 @@ extension PlayerModel {
self.removeQueueItems()
}
backend.closeItem()
if backend != nil {
backend.closeItem()
}
}
@discardableResult func enqueueVideo(