feat: add isSeeking
to onPlaybackStateChanged
(#3899)
* feat: add `isSeeking` to `onPlaybackStateChanged`` * refactor `onSeek` event emit logic * fix rebase
This commit is contained in:
@@ -69,7 +69,7 @@ class VideoEventEmitter {
|
||||
lateinit var onVideoError: (errorString: String, exception: Exception, errorCode: String) -> Unit
|
||||
lateinit var onVideoProgress: (currentPosition: Long, bufferedDuration: Long, seekableDuration: Long, currentPlaybackTime: Double) -> Unit
|
||||
lateinit var onVideoBandwidthUpdate: (bitRateEstimate: Long, height: Int, width: Int, trackId: String) -> Unit
|
||||
lateinit var onVideoPlaybackStateChanged: (isPlaying: Boolean) -> Unit
|
||||
lateinit var onVideoPlaybackStateChanged: (isPlaying: Boolean, isSeeking: Boolean) -> Unit
|
||||
lateinit var onVideoSeek: (currentPosition: Long, seekTime: Long) -> Unit
|
||||
lateinit var onVideoEnd: () -> Unit
|
||||
lateinit var onVideoFullscreenPlayerWillPresent: () -> Unit
|
||||
@@ -158,9 +158,10 @@ class VideoEventEmitter {
|
||||
putString("trackId", trackId)
|
||||
}
|
||||
}
|
||||
onVideoPlaybackStateChanged = { isPlaying ->
|
||||
onVideoPlaybackStateChanged = { isPlaying, isSeeking ->
|
||||
event.dispatch(EventTypes.EVENT_PLAYBACK_STATE_CHANGED) {
|
||||
putBoolean("isPlaying", isPlaying)
|
||||
putBoolean("isSeeking", isSeeking)
|
||||
}
|
||||
}
|
||||
onVideoSeek = { currentPosition, seekTime ->
|
||||
|
@@ -221,6 +221,13 @@ public class ReactExoplayerView extends FrameLayout implements
|
||||
private boolean useCache = false;
|
||||
private ControlsConfig controlsConfig = new ControlsConfig();
|
||||
|
||||
/*
|
||||
* When user is seeking first called is on onPositionDiscontinuity -> DISCONTINUITY_REASON_SEEK
|
||||
* Then we set if to false when playback is back in onIsPlayingChanged -> true
|
||||
*/
|
||||
private boolean isSeeking = false;
|
||||
private long seekPosition = -1;
|
||||
|
||||
// Props from React
|
||||
private Source source = new Source();
|
||||
private boolean repeat;
|
||||
@@ -1618,6 +1625,11 @@ public class ReactExoplayerView extends FrameLayout implements
|
||||
return;
|
||||
}
|
||||
|
||||
if (isPaused && isSeeking && !buffering) {
|
||||
eventEmitter.onVideoSeek.invoke(player.getCurrentPosition(), seekPosition);
|
||||
isSeeking = false;
|
||||
}
|
||||
|
||||
isBuffering = buffering;
|
||||
eventEmitter.onVideoBuffer.invoke(buffering);
|
||||
}
|
||||
@@ -1625,7 +1637,8 @@ public class ReactExoplayerView extends FrameLayout implements
|
||||
@Override
|
||||
public void onPositionDiscontinuity(@NonNull Player.PositionInfo oldPosition, @NonNull Player.PositionInfo newPosition, @Player.DiscontinuityReason int reason) {
|
||||
if (reason == Player.DISCONTINUITY_REASON_SEEK) {
|
||||
eventEmitter.onVideoSeek.invoke(player.getCurrentPosition(), newPosition.positionMs % 1000); // time are in seconds /°\
|
||||
isSeeking = true;
|
||||
seekPosition = newPosition.positionMs;
|
||||
if (isUsingContentResolution) {
|
||||
// We need to update the selected track to make sure that it still matches user selection if track list has changed in this period
|
||||
setSelectedTrack(C.TRACK_TYPE_VIDEO, videoTrackType, videoTrackValue);
|
||||
@@ -1676,7 +1689,15 @@ public class ReactExoplayerView extends FrameLayout implements
|
||||
|
||||
@Override
|
||||
public void onIsPlayingChanged(boolean isPlaying) {
|
||||
eventEmitter.onVideoPlaybackStateChanged.invoke(isPlaying);
|
||||
if (isPlaying && isSeeking) {
|
||||
eventEmitter.onVideoSeek.invoke(player.getCurrentPosition(), seekPosition);
|
||||
}
|
||||
|
||||
eventEmitter.onVideoPlaybackStateChanged.invoke(isPlaying, isSeeking);
|
||||
|
||||
if (isPlaying) {
|
||||
isSeeking = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user