From e83db406a9a0f3cc0ea19fe1de447cfacdd7fddb Mon Sep 17 00:00:00 2001 From: ForgottenUmbrella Date: Mon, 27 Jan 2020 02:12:40 +1100 Subject: [PATCH] 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. --- .../gallery/pro/activities/VideoPlayerActivity.kt | 8 +++++++- .../gallery/pro/fragments/VideoFragment.kt | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/VideoPlayerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/VideoPlayerActivity.kt index 6d0f4f245..6b306ba4c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/VideoPlayerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/VideoPlayerActivity.kt @@ -234,7 +234,13 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen 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) {} diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/fragments/VideoFragment.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/fragments/VideoFragment.kt index 162f98c86..56deff9a1 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/fragments/VideoFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/fragments/VideoFragment.kt @@ -353,7 +353,13 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S 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) {}