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.
Implement ExoPlayer.EventListener
. There is a method onPlayerStateChanged
. When playbackState == ExoPlayer.STATE_READY
then hide your progress indicator.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With