From 5d0ae77a4073037c21a20e0ecb0ca3aa751f956c Mon Sep 17 00:00:00 2001 From: Krzysztof Moch Date: Mon, 13 May 2024 19:35:23 +0200 Subject: [PATCH] chore(ios): store `isBuffering` state --- ios/Video/RCTVideo.swift | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/ios/Video/RCTVideo.swift b/ios/Video/RCTVideo.swift index 9068dc1cd8..b8acd534a2 100644 --- a/ios/Video/RCTVideo.swift +++ b/ios/Video/RCTVideo.swift @@ -80,6 +80,11 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH #endif } } + private var _isBuffering = false { + didSet { + onVideoBuffer?(["isBuffering": _isBuffering, "target": reactTag as Any]) + } + } /* IMA Ads */ private var _adTagUrl: String? @@ -1297,7 +1302,9 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH } func handleReadyForDisplay(changeObject _: Any, change _: NSKeyValueObservedChange) { - onVideoBuffer?(["isBuffering": false, "target": reactTag as Any]) + if _isBuffering { + _isBuffering = false + } onReadyForDisplay?([ "target": reactTag, ]) @@ -1431,16 +1438,16 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH } func handlePlaybackBufferKeyEmpty(playerItem _: AVPlayerItem, change _: NSKeyValueObservedChange) { - onVideoBuffer?(["isBuffering": true, "target": reactTag as Any]) + if !_isBuffering { + _isBuffering = true + } } // Continue playing (or not if paused) after being paused due to hitting an unbuffered zone. func handlePlaybackLikelyToKeepUp(playerItem _: AVPlayerItem, change: NSKeyValueObservedChange) { - if change.newValue == change.oldValue { - return + if _isBuffering { + _isBuffering = false } - - onVideoBuffer?(["isBuffering": false, "target": reactTag as Any]) } func handleTimeControlStatusChange(player: AVPlayer, change: NSKeyValueObservedChange) {