Only fire onSeek once we've completed the seek operation

This commit is contained in:
Hampton Maxwell 2018-11-27 19:48:41 -08:00
parent 5e5315b8c3
commit 413a7b87c6
2 changed files with 16 additions and 8 deletions

View File

@ -110,6 +110,7 @@ class ReactExoplayerView extends FrameLayout implements
private boolean isBuffering; private boolean isBuffering;
private float rate = 1f; private float rate = 1f;
private float audioVolume = 1f; private float audioVolume = 1f;
private long seekTime = C.TIME_UNSET;
private int minBufferMs = DefaultLoadControl.DEFAULT_MIN_BUFFER_MS; private int minBufferMs = DefaultLoadControl.DEFAULT_MIN_BUFFER_MS;
private int maxBufferMs = DefaultLoadControl.DEFAULT_MAX_BUFFER_MS; private int maxBufferMs = DefaultLoadControl.DEFAULT_MAX_BUFFER_MS;
@ -605,7 +606,8 @@ class ReactExoplayerView extends FrameLayout implements
@Override @Override
public void onSeekProcessed() { public void onSeekProcessed() {
// Do nothing. eventEmitter.seek(player.getCurrentPosition(), seekTime);
seekTime = C.TIME_UNSET;
} }
@Override @Override
@ -892,7 +894,7 @@ class ReactExoplayerView extends FrameLayout implements
public void seekTo(long positionMs) { public void seekTo(long positionMs) {
if (player != null) { if (player != null) {
eventEmitter.seek(player.getCurrentPosition(), positionMs); seekTime = positionMs;
player.seekTo(positionMs); player.seekTo(positionMs);
} }
} }

View File

@ -47,6 +47,7 @@ public class ReactVideoView extends ScalableVideoView implements
MediaPlayer.OnPreparedListener, MediaPlayer.OnPreparedListener,
MediaPlayer.OnErrorListener, MediaPlayer.OnErrorListener,
MediaPlayer.OnBufferingUpdateListener, MediaPlayer.OnBufferingUpdateListener,
MediaPlayer.OnSeekCompleteListener,
MediaPlayer.OnCompletionListener, MediaPlayer.OnCompletionListener,
MediaPlayer.OnInfoListener, MediaPlayer.OnInfoListener,
LifecycleEventListener, LifecycleEventListener,
@ -127,6 +128,7 @@ public class ReactVideoView extends ScalableVideoView implements
private float mProgressUpdateInterval = 250.0f; private float mProgressUpdateInterval = 250.0f;
private float mRate = 1.0f; private float mRate = 1.0f;
private float mActiveRate = 1.0f; private float mActiveRate = 1.0f;
private long mSeekTime = 0;
private boolean mPlayInBackground = false; private boolean mPlayInBackground = false;
private boolean mBackgroundPaused = false; private boolean mBackgroundPaused = false;
private boolean mIsFullscreen = false; private boolean mIsFullscreen = false;
@ -213,6 +215,7 @@ public class ReactVideoView extends ScalableVideoView implements
mMediaPlayer.setOnErrorListener(this); mMediaPlayer.setOnErrorListener(this);
mMediaPlayer.setOnPreparedListener(this); mMediaPlayer.setOnPreparedListener(this);
mMediaPlayer.setOnBufferingUpdateListener(this); mMediaPlayer.setOnBufferingUpdateListener(this);
mMediaPlayer.setOnSeekCompleteListener(this);
mMediaPlayer.setOnCompletionListener(this); mMediaPlayer.setOnCompletionListener(this);
mMediaPlayer.setOnInfoListener(this); mMediaPlayer.setOnInfoListener(this);
if (Build.VERSION.SDK_INT >= 23) { if (Build.VERSION.SDK_INT >= 23) {
@ -606,15 +609,18 @@ public class ReactVideoView extends ScalableVideoView implements
mVideoBufferedDuration = (int) Math.round((double) (mVideoDuration * percent) / 100.0); mVideoBufferedDuration = (int) Math.round((double) (mVideoDuration * percent) / 100.0);
} }
public void onSeekComplete(MediaPlayer mp) {
WritableMap event = Arguments.createMap();
event.putDouble(EVENT_PROP_CURRENT_TIME, getCurrentPosition() / 1000.0);
event.putDouble(EVENT_PROP_SEEK_TIME, mSeekTime / 1000.0);
mEventEmitter.receiveEvent(getId(), Events.EVENT_SEEK.toString(), event);
mSeekTime = 0;
}
@Override @Override
public void seekTo(int msec) { public void seekTo(int msec) {
if (mMediaPlayerValid) { if (mMediaPlayerValid) {
WritableMap event = Arguments.createMap(); mSeekTime = msec;
event.putDouble(EVENT_PROP_CURRENT_TIME, getCurrentPosition() / 1000.0);
event.putDouble(EVENT_PROP_SEEK_TIME, msec / 1000.0);
mEventEmitter.receiveEvent(getId(), Events.EVENT_SEEK.toString(), event);
super.seekTo(msec); super.seekTo(msec);
if (isCompleted && mVideoDuration != 0 && msec < mVideoDuration) { if (isCompleted && mVideoDuration != 0 && msec < mVideoDuration) {
isCompleted = false; isCompleted = false;