Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android exoplayer callback when seek is done

I am using exoplayer on Android. I need to show progress indicator when the video is seeking . I can start showing progress indicator on seekTo method but which callback method should I use to hide progress indicator when the seek is done.

like image 633
Prabhu M Avatar asked Jul 18 '16 07:07

Prabhu M


2 Answers

Implement ExoPlayer.EventListener. There is a method onPlayerStateChanged. When playbackState == ExoPlayer.STATE_READY then hide your progress indicator.

like image 173
Sough Avatar answered Sep 30 '22 10:09

Sough


Short answer: Listen to @Sough and use EventListener.onPlaybackStateChanged with STATE_READY.

Long story:

onSeekProcessed() sounds perfect at first, but it is deprecated since v2.12.0 of ExoPlayer with the following comment:

@deprecated Seeks are processed without delay. Listen to #onPositionDiscontinuity(int) with reason #DISCONTINUITY_REASON_SEEK instead.

So onPositionDiscontinuity(int) should be used with the reason DISCONTINUITY_REASON_SEEK.

Somehow this made me wonder if this will really fire at the moment when the seek is done and the video is ready to continue without any delay (as in "onSeekProcessed"). Because, semantically, the moment the seek is initiated could already be interpreted as a position discontinuity (as in "Seeks are processed without delay").

And indeed, when you look at the timing of the events that I measured in a runtime situation, things become obvious:

  0ms - <Seek initiated>
  1ms - onPositionDiscontinuity -> DISCONTINUITY_REASON_SEEK
  2ms - onPlaybackStateChanged -> STATE_BUFFERING
  4ms - onSeekProcessed
208ms - onPlaybackStateChanged -> STATE_READY

This shows that listening for onPlaybackStateChanged with STATE_READY is still the best bet.

Conclusion: onSeekProcessed sounds really good, but it does the wrong thing. So it's deprecated and an alternative is offered. Unfortunately not for the expected thing. Tricky but true.

like image 44
jox Avatar answered Sep 30 '22 12:09

jox