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
This commit is contained in:
Gaëtan Kueny 2024-02-29 14:40:11 +01:00 committed by GitHub
parent ccb60c6dd3
commit 4d4b56c05d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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])
}