From 7d975dfd1326ed3e20ef8578470517cb067695eb Mon Sep 17 00:00:00 2001 From: Kat Huang Date: Mon, 5 Aug 2024 16:08:07 -0600 Subject: [PATCH] Keep startSeek function signature consistent --- ios/Video/RCTVideo.swift | 52 +++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/ios/Video/RCTVideo.swift b/ios/Video/RCTVideo.swift index 3961b259..fc285143 100644 --- a/ios/Video/RCTVideo.swift +++ b/ios/Video/RCTVideo.swift @@ -761,39 +761,41 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH _paused = paused } + + @objc + func setSeek(_ time: NSNumber, _ tolerance: NSNumber) { + 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 - @objc -func setSeek(_ info: NSDictionary!) { - let seekTime: NSNumber! = info["time"] as! NSNumber - let seekTolerance: NSNumber! = info["tolerance"] as! NSNumber - let item: AVPlayerItem? = _player?.currentItem - guard let player = _player, let item = item, item.status == AVPlayerItem.Status.readyToPlay else { - _pendingSeek = true - _pendingSeekTime = seekTime.floatValue - return - } - 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)) - let cmSeekTime = CMTimeMakeWithSeconds(Float64(seekTime.floatValue), preferredTimescale: Int32(NSEC_PER_SEC)) - let tolerance = CMTimeMakeWithSeconds(Float64(seekTolerance.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 } - player.seek(to: cmSeekTime, toleranceBefore: tolerance, toleranceAfter: tolerance) { [weak self] (finished) in - guard let self = self, finished else { return } + self._playerObserver.addTimeObserverIfNotSet() + if !wasPaused { + self.setPaused(false) + } - 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]) + + self.onVideoSeekComplete?(["currentTime": currentTime, + "seekTime": time, + "target": self.reactTag]) } - let currentTime = NSNumber(value: Float(CMTimeGetSeconds(item.currentTime()))) - self.onVideoSeekComplete?(["currentTime": currentTime, - "seekTime": seekTime, - "target": self.reactTag]) + _pendingSeek = false } - _pendingSeek = false -} - @objc func setRate(_ rate: Float) { if _rate != 1 {