From 4905cdf98ee1a98721353ed2abd010af4be858b7 Mon Sep 17 00:00:00 2001 From: Kat Huang Date: Wed, 7 Aug 2024 17:34:25 -0600 Subject: [PATCH 1/4] Add logs --- ios/Video/RCTVideo.swift | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ios/Video/RCTVideo.swift b/ios/Video/RCTVideo.swift index 4d16679a..bb879c21 100644 --- a/ios/Video/RCTVideo.swift +++ b/ios/Video/RCTVideo.swift @@ -114,7 +114,11 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH @objc var onVideoProgress: RCTDirectEventBlock? @objc var onVideoBandwidthUpdate: RCTDirectEventBlock? @objc var onVideoSeek: RCTDirectEventBlock? - @objc var onVideoSeekComplete: RCTDirectEventBlock? + @objc var onVideoSeekComplete: RCTDirectEventBlock? { + didSet { + print("onVideoSeekComplete set: \(onVideoSeekComplete != nil)") + } +} @objc var onVideoEnd: RCTDirectEventBlock? @objc var onTimedMetadata: RCTDirectEventBlock? @objc var onVideoAudioBecomingNoisy: RCTDirectEventBlock? @@ -787,7 +791,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH self.onVideoSeek?(["currentTime": currentTime, "seekTime": time, "target": self.reactTag]) - + print("Seek completed, about to call onVideoSeekComplete") self.onVideoSeekComplete?(["currentTime": currentTime, "seekTime": time, "target": self.reactTag]) -- 2.46.1 From f35da3e5a728354c8ff12954e5e00b3d9a00be66 Mon Sep 17 00:00:00 2001 From: Kat Huang Date: Thu, 8 Aug 2024 16:36:25 -0600 Subject: [PATCH 2/4] add line --- ios/Video/RCTVideo.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/ios/Video/RCTVideo.swift b/ios/Video/RCTVideo.swift index bb879c21..623a48e9 100644 --- a/ios/Video/RCTVideo.swift +++ b/ios/Video/RCTVideo.swift @@ -768,6 +768,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH @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 -- 2.46.1 From ac2162d6f9c2e5e608e807c90de0c8e111b39402 Mon Sep 17 00:00:00 2001 From: Kat Huang Date: Thu, 8 Aug 2024 17:13:01 -0600 Subject: [PATCH 3/4] fix --- ios/Video/RCTVideo.swift | 43 +++++++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/ios/Video/RCTVideo.swift b/ios/Video/RCTVideo.swift index 623a48e9..9fcfb6b1 100644 --- a/ios/Video/RCTVideo.swift +++ b/ios/Video/RCTVideo.swift @@ -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 -- 2.46.1 From 65f13c20c2c9154c0329f8ad1fff911d45ad7cdf Mon Sep 17 00:00:00 2001 From: Kat Huang Date: Thu, 8 Aug 2024 18:38:31 -0600 Subject: [PATCH 4/4] delete logs --- ios/Video/RCTVideo.swift | 4 ---- 1 file changed, 4 deletions(-) diff --git a/ios/Video/RCTVideo.swift b/ios/Video/RCTVideo.swift index 9fcfb6b1..4c9018f6 100644 --- a/ios/Video/RCTVideo.swift +++ b/ios/Video/RCTVideo.swift @@ -780,7 +780,6 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH let seekTime = CMTimeMakeWithSeconds(Float64(time.floatValue), preferredTimescale: Int32(NSEC_PER_SEC)) let toleranceTime = CMTimeMakeWithSeconds(Float64(tolerance.floatValue), preferredTimescale: Int32(NSEC_PER_SEC)) - // Print current time before starting seek let currentTimeBeforeSeek = CMTimeGetSeconds(item.currentTime()) print("Before seek - Current time: \(currentTimeBeforeSeek), Seeking to: \(time)") @@ -798,7 +797,6 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH self._pendingSeek = false guard finished else { - print("Seek operation did not finish successfully") return } @@ -808,10 +806,8 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH } 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": newCurrentTime, "seekTime": time, "target": self.reactTag]) -- 2.46.1