Skip to content

Commit

Permalink
chore(ios): store isBuffering state
Browse files Browse the repository at this point in the history
  • Loading branch information
KrzysztofMoch committed May 13, 2024
1 parent 255dd77 commit 5d0ae77
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions ios/Video/RCTVideo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -1297,7 +1302,9 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
}

func handleReadyForDisplay(changeObject _: Any, change _: NSKeyValueObservedChange<Bool>) {
onVideoBuffer?(["isBuffering": false, "target": reactTag as Any])
if _isBuffering {
_isBuffering = false
}
onReadyForDisplay?([
"target": reactTag,
])
Expand Down Expand Up @@ -1431,16 +1438,16 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
}

func handlePlaybackBufferKeyEmpty(playerItem _: AVPlayerItem, change _: NSKeyValueObservedChange<Bool>) {
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<Bool>) {
if change.newValue == change.oldValue {
return
if _isBuffering {
_isBuffering = false
}

onVideoBuffer?(["isBuffering": false, "target": reactTag as Any])
}

func handleTimeControlStatusChange(player: AVPlayer, change: NSKeyValueObservedChange<AVPlayer.TimeControlStatus>) {
Expand Down

0 comments on commit 5d0ae77

Please sign in to comment.