[Android] Fix wrong initial time when restoring videos

Nicolas Pomepuy git at videolan.org
Thu Mar 4 06:34:10 UTC 2021


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Mon Mar  1 13:13:06 2021 +0100| [d6cbebaea4ec2028d2b2907757a595d593d1cb2f] | committer: Nicolas Pomepuy

Fix wrong initial time when restoring videos

Fixes #1650

> https://code.videolan.org/videolan/vlc-android/commit/d6cbebaea4ec2028d2b2907757a595d593d1cb2f
---

 application/tools/src/main/java/org/videolan/tools/Settings.kt   | 1 +
 .../vlc-android/src/org/videolan/vlc/gui/video/PopupManager.kt   | 9 ++++-----
 .../src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt        | 5 +++--
 3 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/application/tools/src/main/java/org/videolan/tools/Settings.kt b/application/tools/src/main/java/org/videolan/tools/Settings.kt
index 5bc162810..64c4ab128 100644
--- a/application/tools/src/main/java/org/videolan/tools/Settings.kt
+++ b/application/tools/src/main/java/org/videolan/tools/Settings.kt
@@ -67,6 +67,7 @@ const val FORCE_PLAY_ALL = "force_play_all"
 
 const val SCREEN_ORIENTATION = "screen_orientation"
 const val VIDEO_RESUME_TIME = "VideoResumeTime"
+const val VIDEO_RESUME_URI = "VideoResumeUri"
 const val ENABLE_SEEK_BUTTONS = "enable_seek_buttons"
 const val ENABLE_DOUBLE_TAP_SEEK = "enable_double_tap_seek"
 const val ENABLE_VOLUME_GESTURE = "enable_volume_gesture"
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/video/PopupManager.kt b/application/vlc-android/src/org/videolan/vlc/gui/video/PopupManager.kt
index 456d9d72a..1e19a2a42 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/video/PopupManager.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/video/PopupManager.kt
@@ -42,10 +42,7 @@ import org.videolan.medialibrary.interfaces.media.MediaWrapper
 import org.videolan.resources.ACTION_REMOTE_PLAYPAUSE
 import org.videolan.resources.ACTION_REMOTE_STOP
 import org.videolan.resources.ACTION_REMOTE_SWITCH_VIDEO
-import org.videolan.tools.POPUP_KEEPSCREEN
-import org.videolan.tools.Settings
-import org.videolan.tools.VIDEO_RESUME_TIME
-import org.videolan.tools.putSingle
+import org.videolan.tools.*
 import org.videolan.vlc.PlaybackService
 import org.videolan.vlc.R
 import org.videolan.vlc.gui.helpers.MISC_CHANNEL_ID
@@ -238,8 +235,10 @@ class PopupManager constructor(private val service: PlaybackService) : PlaybackS
             // else, go back 2 seconds, to compensate loading time
             time = (if (service.length - time < 5000) 0 else 2000).toLong()
             // Save position
-            if (service.isSeekable)
+            if (service.isSeekable) {
                 Settings.getInstance(service).putSingle(VIDEO_RESUME_TIME, time)
+                service.currentMediaLocation?.let { Settings.getInstance(service).putSingle(VIDEO_RESUME_URI, it) }
+            }
         }
         service.stop()
     }
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt b/application/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt
index eccc0c26d..172e33128 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt
@@ -1729,8 +1729,8 @@ open class VideoPlayerActivity : AppCompatActivity(), PlaybackService.Callback,
                 if (intent.hasExtra(PLAY_EXTRA_ITEM_TITLE))
                     itemTitle = extras.getString(PLAY_EXTRA_ITEM_TITLE)
             }
-            if (startTime == 0L && savedTime > 0L) startTime = savedTime
             val restorePlayback = hasMedia && currentMedia?.uri == videoUri
+            if (startTime == 0L && savedTime > 0L && restorePlayback) startTime = savedTime
 
             var openedMedia: MediaWrapper? = null
             val resumePlaylist = service.isValidIndex(positionInPlaylist)
@@ -1775,7 +1775,8 @@ open class VideoPlayerActivity : AppCompatActivity(), PlaybackService.Callback,
                             return
                         } else {
                             val rTime = settings.getLong(VIDEO_RESUME_TIME, -1L)
-                            if (rTime > 0) {
+                            val lastUri = settings.getString(VIDEO_RESUME_URI, "")
+                            if (rTime > 0 && service.currentMediaLocation == lastUri) {
                                 if (askResume) {
                                     showConfirmResumeDialog()
                                     return



More information about the Android mailing list