Quick seek on ExoPlayer

Viewed 9864

I want to implement a scrubber for ExoPlayer, to show a thumbnail preview of the position the user is seeking to. While my current implementation is working, the thumbnail only refreshes after the user has stopped dragging the seekbar view, or paused for an instant. It appears as if the seek command on ExoPlayer is implementing something like a debounce function, to prevent too many seeks in succession.

While I can work around this by doing my own throttling on the seekbar callback and send a seek request every x milliseconds, I would like to know if there is a way to tell ExoPlayer to not drop seek requests so the thumbnail can update in real time.

For reference, this is my current implementation:

Subject for throttling:

private final Subject<Long> subject = PublishSubject.create();

Observer for seek requests with throttling:

subject
        .throttleLast(400L, TimeUnit.MILLISECONDS)
        .observeOn(AndroidSchedulers.mainThread())
        .subscribe(position -> exoPlayer.seekTo(position));

Seekbar callback:

@Override
public void onProgressChanged(@NonNull final SeekBar seekBar,
                              final int progress,
                              final boolean fromUser) {
    if (fromUser) {
        final long position = computePosition(progress);
        subject.onNext(position);
    }
}
2 Answers

This is old, but might be useful for someone:

As of 2.7.0 ExoPlayer has the method Player.setSeekParameters() If you want to snap the seek position to the closest keyframe use SeekParameters.CLOSEST_SYNC (faster but less accurate). To see to a exact frame (the frame before the requested position, even if it's not a keyframe) use SeekParameters.EXACT.

Related