Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fire onSeek after seek completes on Android, document onSeek #1351

Merged
merged 2 commits into from
Nov 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ var styles = StyleSheet.create({
* [onLoad](#onload)
* [onLoadStart](#onloadstart)
* [onProgress](#onprogress)
* [onSeek](#onseek)
* [onTimedMetadata](#ontimedmetadata)

### Methods
Expand Down Expand Up @@ -848,6 +849,29 @@ Example:

Platforms: all

#### onSeek
Callback function that is called when a seek completes.

Payload:

Property | Type | Description
--- | --- | ---
currentTime | number | The current time after the seek
seekTime | number | The requested time

Example:
```
{
currentTime: 100.5
seekTime: 100
}
```

Both the currentTime & seekTime are reported because the video player may not seek to the exact requested position in order to improve seek performance.


Platforms: Android ExoPlayer, Android MediaPlayer, iOS, Windows UWP

#### onTimedMetadata
Callback function that is called when timed metadata becomes available

Expand Down Expand Up @@ -941,7 +965,7 @@ Platforms: iOS

Seek to the specified position represented by seconds. seconds is a float value.

`seek()` can only be called after the `onLoad` event has fired.
`seek()` can only be called after the `onLoad` event has fired. Once completed, the [onSeek](#onseek) event will be called.

Example:
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ class ReactExoplayerView extends FrameLayout implements
private boolean isBuffering;
private float rate = 1f;
private float audioVolume = 1f;
private long seekTime = C.TIME_UNSET;

private int minBufferMs = DefaultLoadControl.DEFAULT_MIN_BUFFER_MS;
private int maxBufferMs = DefaultLoadControl.DEFAULT_MAX_BUFFER_MS;
Expand Down Expand Up @@ -605,7 +606,8 @@ public void onTimelineChanged(Timeline timeline, Object manifest, int reason) {

@Override
public void onSeekProcessed() {
// Do nothing.
eventEmitter.seek(player.getCurrentPosition(), seekTime);
seekTime = C.TIME_UNSET;
}

@Override
Expand Down Expand Up @@ -892,7 +894,7 @@ public void setVolumeModifier(float volume) {

public void seekTo(long positionMs) {
if (player != null) {
eventEmitter.seek(player.getCurrentPosition(), positionMs);
seekTime = positionMs;
player.seekTo(positionMs);
}
}
Expand Down
18 changes: 12 additions & 6 deletions android/src/main/java/com/brentvatne/react/ReactVideoView.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class ReactVideoView extends ScalableVideoView implements
MediaPlayer.OnPreparedListener,
MediaPlayer.OnErrorListener,
MediaPlayer.OnBufferingUpdateListener,
MediaPlayer.OnSeekCompleteListener,
MediaPlayer.OnCompletionListener,
MediaPlayer.OnInfoListener,
LifecycleEventListener,
Expand Down Expand Up @@ -127,6 +128,7 @@ public String toString() {
private float mProgressUpdateInterval = 250.0f;
private float mRate = 1.0f;
private float mActiveRate = 1.0f;
private long mSeekTime = 0;
private boolean mPlayInBackground = false;
private boolean mBackgroundPaused = false;
private boolean mIsFullscreen = false;
Expand Down Expand Up @@ -213,6 +215,7 @@ private void initializeMediaPlayerIfNeeded() {
mMediaPlayer.setOnErrorListener(this);
mMediaPlayer.setOnPreparedListener(this);
mMediaPlayer.setOnBufferingUpdateListener(this);
mMediaPlayer.setOnSeekCompleteListener(this);
mMediaPlayer.setOnCompletionListener(this);
mMediaPlayer.setOnInfoListener(this);
if (Build.VERSION.SDK_INT >= 23) {
Expand Down Expand Up @@ -606,15 +609,18 @@ public void onBufferingUpdate(MediaPlayer mp, int percent) {
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
public void seekTo(int msec) {

if (mMediaPlayerValid) {
WritableMap event = Arguments.createMap();
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);

mSeekTime = msec;
super.seekTo(msec);
if (isCompleted && mVideoDuration != 0 && msec < mVideoDuration) {
isCompleted = false;
Expand Down