From 677e68332ca29eeb9568a36207b4adfdb889482f Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 2 Jan 2019 18:25:17 +0100 Subject: [PATCH] remember last video playback position if set so --- .../pro/activities/VideoPlayerActivity.kt | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) 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 9d565482a..56d2e4a30 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 @@ -77,6 +77,10 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen override fun onPause() { super.onPause() pauseVideo() + + if (config.rememberLastVideoPosition && mWasVideoStarted) { + saveVideoProgress() + } } override fun onDestroy() { @@ -224,6 +228,11 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen video_seekbar.max = mDuration video_duration.text = mDuration.getFormattedDuration() setPosition(mCurrTime) + + if (config.rememberLastVideoPosition) { + setLastVideoSavedPosition() + } + playVideo() } } @@ -272,6 +281,12 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen video_curr_time.text = seconds.getFormattedDuration() } + private fun setLastVideoSavedPosition() { + if (config.lastVideoPath == mUri.toString() && config.lastVideoPosition > 0) { + setPosition(config.lastVideoPosition) + } + } + private fun videoCompleted() { } @@ -282,6 +297,15 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen return currentPos != 0L && currentPos >= duration } + private fun saveVideoProgress() { + if (!videoEnded()) { + config.apply { + lastVideoPosition = mExoPlayer!!.currentPosition.toInt() / 1000 + lastVideoPath = mUri.toString() + } + } + } + private fun setVideoSize() { val videoProportion = mVideoSize.x.toFloat() / mVideoSize.y.toFloat() val display = windowManager.defaultDisplay