fix: ensure progress is sent before onEnd
callback (#3872)
* fix: add onProgress event before onEnd
This commit is contained in:
@@ -312,7 +312,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
||||
|
||||
// MARK: - Progress
|
||||
|
||||
func sendProgressUpdate() {
|
||||
func sendProgressUpdate(didEnd: Bool = false) {
|
||||
#if !USE_GOOGLE_IMA
|
||||
// If we dont use Ads and onVideoProgress is not defined we dont need to run this code
|
||||
guard onVideoProgress != nil else { return }
|
||||
@@ -334,11 +334,11 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
||||
}
|
||||
let currentPlaybackTime = _player?.currentItem?.currentDate()
|
||||
let duration = CMTimeGetSeconds(playerDuration)
|
||||
let currentTimeSecs = CMTimeGetSeconds(currentTime ?? .zero)
|
||||
var currentTimeSecs = CMTimeGetSeconds(currentTime ?? .zero)
|
||||
|
||||
NotificationCenter.default.post(name: NSNotification.Name("RCTVideo_progress"), object: nil, userInfo: [
|
||||
"progress": NSNumber(value: currentTimeSecs / duration),
|
||||
])
|
||||
if currentTimeSecs > duration || didEnd {
|
||||
currentTimeSecs = duration
|
||||
}
|
||||
|
||||
if currentTimeSecs >= 0 {
|
||||
#if USE_GOOGLE_IMA
|
||||
@@ -348,10 +348,10 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
||||
}
|
||||
#endif
|
||||
onVideoProgress?([
|
||||
"currentTime": NSNumber(value: Float(currentTimeSecs)),
|
||||
"currentTime": currentTimeSecs,
|
||||
"playableDuration": RCTVideoUtils.calculatePlayableDuration(_player, withSource: _source),
|
||||
"atValue": NSNumber(value: currentTime?.value ?? .zero),
|
||||
"currentPlaybackTime": NSNumber(value: NSNumber(value: Double(currentPlaybackTime?.timeIntervalSince1970 ?? 0 * 1000)).int64Value),
|
||||
"atValue": currentTime?.value ?? .zero,
|
||||
"currentPlaybackTime": NSNumber(value: Double(currentPlaybackTime?.timeIntervalSince1970 ?? 0 * 1000)).int64Value,
|
||||
"target": reactTag,
|
||||
"seekableDuration": RCTVideoUtils.calculateSeekableDuration(_player),
|
||||
])
|
||||
@@ -1570,6 +1570,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
||||
|
||||
@objc
|
||||
func handlePlayerItemDidReachEnd(notification: NSNotification!) {
|
||||
sendProgressUpdate(didEnd: true)
|
||||
onVideoEnd?(["target": reactTag as Any])
|
||||
#if USE_GOOGLE_IMA
|
||||
if notification.object as? AVPlayerItem == _player?.currentItem {
|
||||
|
Reference in New Issue
Block a user