Compare commits
8 Commits
kat/androi
...
master
Author | SHA1 | Date | |
---|---|---|---|
f72b44d4df | |||
d2ab22b99f | |||
2dcde42fd6 | |||
c7a45d421b | |||
f0db0a6868 | |||
01b3322e03 | |||
13beae1401 | |||
f3deabd75e |
@ -229,6 +229,7 @@ public class ReactExoplayerView extends FrameLayout implements
|
||||
*/
|
||||
private boolean isSeeking = false;
|
||||
private long seekPosition = -1;
|
||||
private boolean isSeekInProgress = false;
|
||||
|
||||
// Props from React
|
||||
private Source source = new Source();
|
||||
@ -305,11 +306,12 @@ public class ReactExoplayerView extends FrameLayout implements
|
||||
};
|
||||
|
||||
private void handleSeekCompletion() {
|
||||
if (player != null && player.getPlaybackState() == Player.STATE_READY) {
|
||||
Log.d("ReactExoplayerView", "onSeekComplete triggered. Current position: " + player.getCurrentPosition());
|
||||
if (player != null && player.getPlaybackState() == Player.STATE_READY && isSeekInProgress) {
|
||||
Log.d("ReactExoplayerView", "handleSeekCompletion: currentPosition=" + player.getCurrentPosition());
|
||||
eventEmitter.onVideoSeekComplete.invoke(player.getCurrentPosition());
|
||||
isSeeking = false;
|
||||
seekPosition = -1;
|
||||
isSeekInProgress = false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1349,6 +1351,7 @@ public class ReactExoplayerView extends FrameLayout implements
|
||||
if (events.contains(Player.EVENT_PLAYBACK_STATE_CHANGED) || events.contains(Player.EVENT_PLAY_WHEN_READY_CHANGED)) {
|
||||
int playbackState = player.getPlaybackState();
|
||||
boolean playWhenReady = player.getPlayWhenReady();
|
||||
Log.d("ReactExoplayerView", "onEvents: playbackState=" + playbackState + ", playWhenReady=" + playWhenReady);
|
||||
String text = "onStateChanged: playWhenReady=" + playWhenReady + ", playbackState=";
|
||||
eventEmitter.onPlaybackRateChange.invoke(playWhenReady && playbackState == ExoPlayer.STATE_READY ? 1.0f : 0.0f);
|
||||
switch (playbackState) {
|
||||
@ -1382,7 +1385,10 @@ public class ReactExoplayerView extends FrameLayout implements
|
||||
playerControlView.show();
|
||||
}
|
||||
setKeepScreenOn(preventsDisplaySleepDuringVideoPlayback);
|
||||
handleSeekCompletion();
|
||||
Log.d("ReactExoplayerView", "Player STATE_READY: currentPosition=" + player.getCurrentPosition());
|
||||
if (isSeekInProgress) {
|
||||
handleSeekCompletion();
|
||||
}
|
||||
break;
|
||||
case Player.STATE_ENDED:
|
||||
text += "ended";
|
||||
@ -1646,6 +1652,7 @@ public class ReactExoplayerView extends FrameLayout implements
|
||||
|
||||
@Override
|
||||
public void onPositionDiscontinuity(@NonNull Player.PositionInfo oldPosition, @NonNull Player.PositionInfo newPosition, @Player.DiscontinuityReason int reason) {
|
||||
Log.d("ReactExoplayerView", "onPositionDiscontinuity: reason=" + reason + ", oldPosition=" + oldPosition.positionMs + ", newPosition=" + newPosition.positionMs);
|
||||
if (reason == Player.DISCONTINUITY_REASON_SEEK) {
|
||||
isSeeking = true;
|
||||
seekPosition = newPosition.positionMs;
|
||||
@ -2149,6 +2156,8 @@ public class ReactExoplayerView extends FrameLayout implements
|
||||
|
||||
public void seekTo(long positionMs) {
|
||||
if (player != null) {
|
||||
Log.d("ReactExoplayerView", "seekTo: positionMs=" + positionMs);
|
||||
isSeekInProgress = true;
|
||||
isSeeking = true;
|
||||
seekPosition = positionMs;
|
||||
player.seekTo(positionMs);
|
||||
|
@ -762,6 +762,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
||||
_paused = paused
|
||||
}
|
||||
|
||||
|
||||
@objc
|
||||
func setSeek(_ time: NSNumber, _ tolerance: NSNumber) {
|
||||
let item: AVPlayerItem? = _player?.currentItem
|
||||
@ -770,30 +771,44 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
||||
_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 }
|
||||
let currentTimeBeforeSeek = CMTimeGetSeconds(item.currentTime())
|
||||
|
||||
// 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 {
|
||||
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())
|
||||
|
||||
self.onVideoSeekComplete?(["currentTime": currentTime,
|
||||
"seekTime": time,
|
||||
"target": self.reactTag])
|
||||
let newCurrentTime = NSNumber(value: Float(currentTimeAfterSeek))
|
||||
self.onVideoSeekComplete?(["currentTime": newCurrentTime,
|
||||
"seekTime": time,
|
||||
"target": self.reactTag])
|
||||
}
|
||||
|
||||
_pendingSeek = false
|
||||
player.seek(to: seekTime, toleranceBefore: toleranceTime, toleranceAfter: toleranceTime, completionHandler: seekCompletionHandler)
|
||||
}
|
||||
|
||||
@objc
|
||||
@ -1661,3 +1676,4 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
||||
@objc
|
||||
func setOnClick(_: Any) {}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user