[Android] Correctly save current video play queue

Geoffrey Métais git at videolan.org
Thu Feb 20 15:17:12 CET 2020


vlc-android | branch: 3.2.x | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Feb 20 15:05:01 2020 +0100| [34f04a1b84b4059b2143d1d05376303deb80f4cb] | committer: Geoffrey Métais

Correctly save current video play queue

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

 vlc-android/src/org/videolan/vlc/PlaybackService.kt        |  6 +++---
 vlc-android/src/org/videolan/vlc/gui/video/PopupManager.kt |  2 +-
 .../src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt  |  4 ++--
 vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt  | 14 +++++++-------
 4 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/PlaybackService.kt b/vlc-android/src/org/videolan/vlc/PlaybackService.kt
index b4b48ca08..d8102bc46 100644
--- a/vlc-android/src/org/videolan/vlc/PlaybackService.kt
+++ b/vlc-android/src/org/videolan/vlc/PlaybackService.kt
@@ -548,7 +548,7 @@ class PlaybackService : MediaBrowserServiceCompat(), CoroutineScope, LifecycleOw
         handler.removeCallbacksAndMessages(null)
         if (this::mediaSession.isInitialized) mediaSession.release()
         //Call it once mediaSession is null, to not publish playback state
-        stop(true)
+        stop(systemExit = true)
 
         unregisterReceiver(receiver)
         playlistManager.onServiceDestroyed()
@@ -747,8 +747,8 @@ class PlaybackService : MediaBrowserServiceCompat(), CoroutineScope, LifecycleOw
 
     @MainThread
     @JvmOverloads
-    fun stop(systemExit: Boolean = false) {
-        playlistManager.stop(systemExit)
+    fun stop(systemExit: Boolean = false, video: Boolean = false) {
+        playlistManager.stop(systemExit = systemExit, video = video)
     }
 
     private fun initMediaSession() {
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/PopupManager.kt b/vlc-android/src/org/videolan/vlc/gui/video/PopupManager.kt
index c395329f2..d2a6cc12b 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/PopupManager.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/video/PopupManager.kt
@@ -236,7 +236,7 @@ class PopupManager constructor(private val mService: PlaybackService) : Playback
                 Settings.getInstance(mService).edit()
                         .putLong(VIDEO_RESUME_TIME, time).apply()
         }
-        mService.stop()
+        mService.stop(video = true)
     }
 
     private fun showNotification() {
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt
index 398437df6..f23df44b8 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt
@@ -771,7 +771,7 @@ open class VideoPlayerActivity : AppCompatActivity(), IPlaybackSettingsControlle
             val vlcVout = vout
             if (vlcVout != null && vlcVout.areViewsAttached()) {
                 if (isPlayingPopup) {
-                    stop()
+                    stop(video = true)
                 } else
                     vlcVout.detachViews()
             }
@@ -877,7 +877,7 @@ open class VideoPlayerActivity : AppCompatActivity(), IPlaybackSettingsControlle
                 else
                     savedTime -= 2000 // go back 2 seconds, to compensate loading time
             }
-            stop()
+            stop(video = true)
         }
     }
 
diff --git a/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt b/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
index a951489d6..6875e7776 100644
--- a/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
+++ b/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
@@ -204,12 +204,12 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
         launch { playIndex(currentIndex) }
     }
 
-    fun stop(systemExit: Boolean = false) {
+    fun stop(systemExit: Boolean = false, video: Boolean = false) {
         clearABRepeat()
         stopAfter = -1
         videoBackground = false
         getCurrentMedia()?.let {
-            savePosition()
+            savePosition(video = video)
             val audio = isAudioList() // check before dispatching in saveMediaMeta()
             launch(start = CoroutineStart.UNDISPATCHED) {
                 saveMediaMeta().join()
@@ -321,7 +321,7 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
 
     private fun skipMedia() {
         if (currentIndex != nextIndex) next()
-        else stop(false)
+        else stop(systemExit = false)
     }
 
     fun onServiceDestroyed() {
@@ -630,10 +630,10 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
     }
 
     @Synchronized
-    private fun savePosition(reset: Boolean = false) {
+    private fun savePosition(reset: Boolean = false, video: Boolean = false) {
         if (!hasMedia()) return
         val editor = settings.edit()
-        val audio = isAudioList()
+        val audio = !video && isAudioList()
         editor.putBoolean(if (audio) "audio_shuffling" else "media_shuffling", shuffling)
         editor.putInt(if (audio) "position_in_audio_list" else "position_in_media_list", if (reset) 0 else currentIndex)
         editor.putLong(if (audio) "position_in_song" else "position_in_media", if (reset) 0L else player.getCurrentTime())
@@ -748,7 +748,7 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
                     if (newMedia) {
                         loadMediaMeta(mw)
                         saveMediaList()
-                        savePosition(true)
+                        savePosition(reset = true)
                         saveCurrentMedia()
                         newMedia = false
                         if (player.hasRenderer || !player.isVideoPlaying()) showAudioPlayer.value = true
@@ -760,7 +760,7 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
                     if (currentIndex != nextIndex) {
                         saveMediaMeta()
                         if (isBenchmark) player.setPreviousStats()
-                        if (nextIndex == -1) savePosition(true)
+                        if (nextIndex == -1) savePosition(reset = true)
                     }
                     if (stopAfter == currentIndex) {
                         stop()



More information about the Android mailing list