From 4d4b56c05dd3c09fce5ddc38f56b0391c357ac85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Kueny?= Date: Thu, 29 Feb 2024 14:40:11 +0100 Subject: [PATCH] fix(ios): Do not crash when accessLog return nil (#3549) accessLog method can return nil if no logging information are currently available (see https://developer.apple.com/documentation/avfoundation/avplayeritem/1388499-accesslog). So we handle this case & do not call onVideoBandwidthUpdate fix https://github.com/react-native-video/react-native-video/issues/3424 --- ios/Video/RCTVideo.swift | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ios/Video/RCTVideo.swift b/ios/Video/RCTVideo.swift index 6f4cf581..49fe1705 100644 --- a/ios/Video/RCTVideo.swift +++ b/ios/Video/RCTVideo.swift @@ -1374,9 +1374,11 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH @objc func handleAVPlayerAccess(notification: NSNotification!) { - let accessLog: AVPlayerItemAccessLog! = (notification.object as! AVPlayerItem).accessLog() - let lastEvent: AVPlayerItemAccessLogEvent! = accessLog.events.last + guard let accessLog = (notification.object as? AVPlayerItem)?.accessLog() else { + return + } + guard let lastEvent = accessLog.events.last else { return } onVideoBandwidthUpdate?(["bitrate": lastEvent.observedBitrate, "target": reactTag]) }