From 7d758178d570ece81741a56ce729f56ae5b3e9b7 Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 2 Jan 2019 18:32:03 +0100 Subject: [PATCH] loop videos after ending if desired --- .../pro/activities/VideoPlayerActivity.kt | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 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 56d2e4a30..a6117563a 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 @@ -242,7 +242,7 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen return } - val wasEnded = videoEnded() + val wasEnded = didVideoEnd() if (wasEnded) { setPosition(0) } @@ -259,7 +259,7 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen } mIsPlaying = false - if (!videoEnded()) { + if (!didVideoEnd()) { mExoPlayer?.playWhenReady = false } @@ -288,17 +288,29 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen } private fun videoCompleted() { + if (mExoPlayer == null) { + return + } + clearLastVideoSavedProgress() + mCurrTime = (mExoPlayer!!.duration / 1000).toInt() + if (config.loopVideos) { + playVideo() + } else { + video_seekbar.progress = video_seekbar.max + video_curr_time.text = mDuration.getFormattedDuration() + pauseVideo() + } } - private fun videoEnded(): Boolean { + private fun didVideoEnd(): Boolean { val currentPos = mExoPlayer?.currentPosition ?: 0 val duration = mExoPlayer?.duration ?: 0 return currentPos != 0L && currentPos >= duration } private fun saveVideoProgress() { - if (!videoEnded()) { + if (!didVideoEnd()) { config.apply { lastVideoPosition = mExoPlayer!!.currentPosition.toInt() / 1000 lastVideoPath = mUri.toString() @@ -306,6 +318,13 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen } } + private fun clearLastVideoSavedProgress() { + config.apply { + lastVideoPosition = 0 + lastVideoPath = "" + } + } + private fun setVideoSize() { val videoProportion = mVideoSize.x.toFloat() / mVideoSize.y.toFloat() val display = windowManager.defaultDisplay