Add onSeekComplete callaback to ios video player
This commit is contained in:
parent
38aa2b057a
commit
18a0d234dd
@ -114,6 +114,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
||||
@objc var onVideoProgress: RCTDirectEventBlock?
|
||||
@objc var onVideoBandwidthUpdate: RCTDirectEventBlock?
|
||||
@objc var onVideoSeek: RCTDirectEventBlock?
|
||||
@objc var onVideoSeekComplete: RCTDirectEventBlock?
|
||||
@objc var onVideoEnd: RCTDirectEventBlock?
|
||||
@objc var onTimedMetadata: RCTDirectEventBlock?
|
||||
@objc var onVideoAudioBecomingNoisy: RCTDirectEventBlock?
|
||||
@ -762,34 +763,36 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
||||
}
|
||||
|
||||
@objc
|
||||
func setSeek(_ time: NSNumber, _ tolerance: NSNumber) {
|
||||
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
|
||||
|
||||
guard item != nil, let player = _player, let item, item.status == AVPlayerItem.Status.readyToPlay else {
|
||||
_pendingSeekTime = time.floatValue
|
||||
_pendingSeekTime = seekTime.floatValue
|
||||
return
|
||||
}
|
||||
let wasPaused = _paused
|
||||
|
||||
RCTPlayerOperations.seek(
|
||||
player: player,
|
||||
playerItem: item,
|
||||
paused: _paused,
|
||||
seekTime: time.floatValue,
|
||||
seekTolerance: tolerance.floatValue
|
||||
) { [weak self] (_: Bool) in
|
||||
guard let self else { return }
|
||||
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: cmSeekTime, toleranceBefore: tolerance, toleranceAfter: tolerance) { [weak self] (finished) in
|
||||
guard let self = self, finished else { return }
|
||||
|
||||
self._playerObserver.addTimeObserverIfNotSet()
|
||||
self.setPaused(self._paused)
|
||||
self.onVideoSeek?(["currentTime": NSNumber(value: Float(CMTimeGetSeconds(item.currentTime()))),
|
||||
"seekTime": time,
|
||||
if !wasPaused {
|
||||
self.setPaused(false)
|
||||
}
|
||||
|
||||
let currentTime = NSNumber(value: Float(CMTimeGetSeconds(item.currentTime())))
|
||||
self.onVideoSeekComplete?(["currentTime": currentTime,
|
||||
"seekTime": seekTime,
|
||||
"target": self.reactTag])
|
||||
}
|
||||
|
||||
_pendingSeek = false
|
||||
}
|
||||
}
|
||||
|
||||
@objc
|
||||
func setRate(_ rate: Float) {
|
||||
|
@ -46,6 +46,7 @@ RCT_EXPORT_VIEW_PROPERTY(onVideoError, RCTDirectEventBlock);
|
||||
RCT_EXPORT_VIEW_PROPERTY(onVideoProgress, RCTDirectEventBlock);
|
||||
RCT_EXPORT_VIEW_PROPERTY(onVideoBandwidthUpdate, RCTDirectEventBlock);
|
||||
RCT_EXPORT_VIEW_PROPERTY(onVideoSeek, RCTDirectEventBlock);
|
||||
RCT_EXPORT_VIEW_PROPERTY(onVideoSeekComplete, RCTDirectEventBlock);
|
||||
RCT_EXPORT_VIEW_PROPERTY(onVideoEnd, RCTDirectEventBlock);
|
||||
RCT_EXPORT_VIEW_PROPERTY(onTimedMetadata, RCTDirectEventBlock);
|
||||
RCT_EXPORT_VIEW_PROPERTY(onVideoAudioBecomingNoisy, RCTDirectEventBlock);
|
||||
|
Loading…
Reference in New Issue
Block a user