This commit is contained in:
Kat Huang 2024-08-08 17:13:01 -06:00
parent f35da3e5a7
commit ac2162d6f9

View File

@ -766,39 +766,58 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
_paused = paused
}
@objc
func setSeek(_ time: NSNumber, _ tolerance: NSNumber) {
print("KAT IOS FIRST LINE OF SET SEEK")
let item: AVPlayerItem? = _player?.currentItem
guard item != nil, let player = _player, let item, item.status == AVPlayerItem.Status.readyToPlay else {
_pendingSeek = true
_pendingSeekTime = time.floatValue
return
}
let wasPaused = _paused
let wasPaused = _paused
let seekTime = CMTimeMakeWithSeconds(Float64(time.floatValue), preferredTimescale: Int32(NSEC_PER_SEC))
let toleranceTime = CMTimeMakeWithSeconds(Float64(tolerance.floatValue), preferredTimescale: Int32(NSEC_PER_SEC))
player.seek(to: seekTime, toleranceBefore: toleranceTime, toleranceAfter: toleranceTime) { [weak self] (finished) in
guard let self = self, finished else { return }
// Print current time before starting seek
let currentTimeBeforeSeek = CMTimeGetSeconds(item.currentTime())
print("Before seek - Current time: \(currentTimeBeforeSeek), Seeking to: \(time)")
// Call onVideoSeek before starting the seek operation
let currentTime = NSNumber(value: Float(currentTimeBeforeSeek))
self.onVideoSeek?(["currentTime": currentTime,
"seekTime": time,
"target": self.reactTag])
_pendingSeek = true
let seekCompletionHandler: (Bool) -> Void = { [weak self] finished in
guard let self = self else { return }
self._pendingSeek = false
guard finished else {
print("Seek operation did not finish successfully")
return
}
self._playerObserver.addTimeObserverIfNotSet()
if !wasPaused {
self.setPaused(false)
}
let currentTime = NSNumber(value: Float(CMTimeGetSeconds(item.currentTime())))
self.onVideoSeek?(["currentTime": currentTime,
"seekTime": time,
"target": self.reactTag])
let currentTimeAfterSeek = CMTimeGetSeconds(item.currentTime())
print("After seek - Current time: \(currentTimeAfterSeek), Sought to: \(time)")
let newCurrentTime = NSNumber(value: Float(currentTimeAfterSeek))
print("Seek completed, about to call onVideoSeekComplete")
self.onVideoSeekComplete?(["currentTime": currentTime,
"seekTime": time,
"target": self.reactTag])
self.onVideoSeekComplete?(["currentTime": newCurrentTime,
"seekTime": time,
"target": self.reactTag])
}
_pendingSeek = false
player.seek(to: seekTime, toleranceBefore: toleranceTime, toleranceAfter: toleranceTime, completionHandler: seekCompletionHandler)
}
@objc