Reset progress views on video loop

The previous loop method of seeking to the beginning at video completion ensured
that the seekbar and current time text were immediately reset. Using ExoPlayer's
own implementation of video looping means that `Player.STATE_ENDED` is no longer
reached, thus the UI no longer accurately tracks progress. Restore the old
behaviour by resetting the views on position discontinuity.
This commit is contained in:
ForgottenUmbrella 2020-01-27 02:12:40 +11:00
parent f8315438d8
commit e83db406a9
2 changed files with 14 additions and 2 deletions

View file

@ -234,7 +234,13 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen
override fun onLoadingChanged(isLoading: Boolean) {} override fun onLoadingChanged(isLoading: Boolean) {}
override fun onPositionDiscontinuity(reason: Int) {} override fun onPositionDiscontinuity(reason: Int) {
// Reset progress views when video loops.
if (reason == Player.DISCONTINUITY_REASON_PERIOD_TRANSITION) {
video_seekbar.progress = 0
video_curr_time.text = 0.getFormattedDuration()
}
}
override fun onRepeatModeChanged(repeatMode: Int) {} override fun onRepeatModeChanged(repeatMode: Int) {}

View file

@ -353,7 +353,13 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
override fun onLoadingChanged(isLoading: Boolean) {} override fun onLoadingChanged(isLoading: Boolean) {}
override fun onPositionDiscontinuity(reason: Int) {} override fun onPositionDiscontinuity(reason: Int) {
// Reset progress views when video loops.
if (reason == Player.DISCONTINUITY_REASON_PERIOD_TRANSITION) {
mSeekBar.progress = 0
mCurrTimeView.text = 0.getFormattedDuration()
}
}
override fun onRepeatModeChanged(repeatMode: Int) {} override fun onRepeatModeChanged(repeatMode: Int) {}