From d1d2be64834a3e6843b18c265607747a541b1742 Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 1 Apr 2019 16:35:33 +0200 Subject: [PATCH] fixing some video playback glitches --- .../gallery/pro/fragments/VideoFragment.kt | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) 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 1f220e798..890654b1d 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 @@ -49,8 +49,11 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S private var mIsPlaying = false private var mIsDragged = false private var mWasVideoStarted = false + private var mWasPlayerInited = false + private var mWasLastPositionRestored = false private var mCurrTime = 0 private var mDuration = 0 + private var mPositionWhenInit = 0 private var mExoPlayer: SimpleExoPlayer? = null private var mVideoSize = Point(0, 0) @@ -496,6 +499,9 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) { if (mExoPlayer != null && fromUser) { + if (!mWasPlayerInited) { + mPositionWhenInit = progress + } setPosition(progress) } } @@ -553,7 +559,8 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S setPosition(0) } - if (mStoredRememberLastVideoPosition) { + if (mStoredRememberLastVideoPosition && !mWasLastPositionRestored) { + mWasLastPositionRestored = true restoreLastVideoSavedPosition() } @@ -614,6 +621,12 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S playVideo() } } + + if (mPositionWhenInit != 0 && !mWasPlayerInited) { + setPosition(mPositionWhenInit) + mPositionWhenInit = 0 + } + mWasPlayerInited = true } private fun videoCompleted() {