[Android] PlaylistManager: split repeatType for audio/video

Duncan McNamara git at videolan.org
Tue Jul 12 09:57:19 UTC 2022


vlc-android | branch: master | Duncan McNamara <dcn.mcnamara at gmail.com> | Thu Jul  7 15:53:43 2022 +0200| [f07febfc1f5191d1b96c34c168256f0508d82fbe] | committer: Nicolas Pomepuy

PlaylistManager: split repeatType for audio/video

Users should be able to have a different repeat type for watching videos
or listening to music as these are different use cases.

Fixes #2587

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

 .../src/org/videolan/vlc/media/PlaylistManager.kt   | 21 ++++++++++++++++++---
 .../src/org/videolan/vlc/util/VersionMigration.kt   | 21 ++++++++++++++++++++-
 2 files changed, 38 insertions(+), 4 deletions(-)

diff --git a/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt b/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
index c2c476bdf..40b2fa225 100644
--- a/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
+++ b/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
@@ -37,7 +37,8 @@ import kotlin.math.max
 
 private const val TAG = "VLC/PlaylistManager"
 private const val PREVIOUS_LIMIT_DELAY = 5000L
-private const val PLAYLIST_REPEAT_MODE_KEY = "audio_repeat_mode" //we keep the old string for migration reasons
+private const val PLAYLIST_AUDIO_REPEAT_MODE_KEY = "audio_repeat_mode"
+private const val PLAYLIST_VIDEO_REPEAT_MODE_KEY = "video_repeat_mode"
 
 class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventListener, IMedia.EventListener, CoroutineScope {
     override val coroutineContext = Dispatchers.Main.immediate + SupervisorJob()
@@ -92,7 +93,7 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
     private var shouldDisableCookieForwarding: Boolean = false
 
     init {
-        repeating = settings.getInt(PLAYLIST_REPEAT_MODE_KEY, PlaybackStateCompat.REPEAT_MODE_NONE)
+        repeating = settings.getInt(PLAYLIST_AUDIO_REPEAT_MODE_KEY, PlaybackStateCompat.REPEAT_MODE_NONE)
         resetResumeStatus()
     }
 
@@ -344,10 +345,23 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
         launch { determinePrevAndNextIndices() }
     }
 
+    /**
+     * Will set the repeating variable from the value that has been saved in settings
+     */
+    private fun setRepeatTypeFromSettings() {
+        repeating = if (getCurrentMedia()?.type == MediaWrapper.TYPE_VIDEO) {
+            settings.getInt(PLAYLIST_VIDEO_REPEAT_MODE_KEY, PlaybackStateCompat.REPEAT_MODE_NONE)
+        } else
+            settings.getInt(PLAYLIST_AUDIO_REPEAT_MODE_KEY, PlaybackStateCompat.REPEAT_MODE_NONE)
+    }
+
     @MainThread
     fun setRepeatType(repeatType: Int) {
         repeating = repeatType
-        settings.putSingle(PLAYLIST_REPEAT_MODE_KEY, repeating)
+        if (getCurrentMedia()?.type == MediaWrapper.TYPE_VIDEO)
+            settings.putSingle(PLAYLIST_VIDEO_REPEAT_MODE_KEY, repeating)
+        else
+            settings.putSingle(PLAYLIST_AUDIO_REPEAT_MODE_KEY, repeating)
         savePosition()
         launch { determinePrevAndNextIndices() }
     }
@@ -372,6 +386,7 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
 
         val mw = mediaList.getMedia(index) ?: return
         val isVideoPlaying = mw.type == MediaWrapper.TYPE_VIDEO && player.isVideoPlaying()
+        setRepeatTypeFromSettings()
         if (!videoBackground && isVideoPlaying) mw.addFlags(MediaWrapper.MEDIA_VIDEO)
         if (videoBackground) mw.addFlags(MediaWrapper.MEDIA_FORCE_AUDIO)
         if (isBenchmark) mw.addFlags(MediaWrapper.MEDIA_BENCHMARK)
diff --git a/application/vlc-android/src/org/videolan/vlc/util/VersionMigration.kt b/application/vlc-android/src/org/videolan/vlc/util/VersionMigration.kt
index 3f84f6580..1d217b700 100644
--- a/application/vlc-android/src/org/videolan/vlc/util/VersionMigration.kt
+++ b/application/vlc-android/src/org/videolan/vlc/util/VersionMigration.kt
@@ -39,7 +39,7 @@ import org.videolan.vlc.gui.onboarding.ONBOARDING_DONE_KEY
 import java.io.File
 import java.io.IOException
 
-private const val CURRENT_VERSION = 6
+private const val CURRENT_VERSION = 7
 
 object VersionMigration {
 
@@ -64,6 +64,10 @@ object VersionMigration {
         if (lastVersion < 6) {
             migrateToVersion6(settings)
         }
+        if (lastVersion < 7) {
+            migrateToVersion7(settings)
+        }
+
         settings.putSingle(KEY_CURRENT_SETTINGS_VERSION, CURRENT_VERSION)
     }
 
@@ -158,4 +162,19 @@ object VersionMigration {
         if (hudTimeOut == 0) settings.edit { putInt(VIDEO_HUD_TIMEOUT, 16) }
         Settings.videoHudDelay = settings.getInt(VIDEO_HUD_TIMEOUT, 4).coerceInOrDefault(1,15,-1)
     }
+
+    /**
+     * Migrate the PLAYLIST_REPEAT_MODE_KEY from the PlaylistManager to split it in two
+     * audio / video separate preferences, PLAYLIST_VIDEO_REPEAT_MODE_KEY and
+     * PLAYLIST_AUDIO_REPEAT_MODE_KEY, but keep the value previously set by the user
+     */
+    private fun migrateToVersion7(settings: SharedPreferences) {
+        Log.i(this::class.java.simpleName, "Migrating to Version 7: migrate PlaylistManager " +
+                "PLAYLIST_REPEASE_MODE_KEY to PLAYLIST_VIDEO_REPEAT_MODE_KEY " + 
+                "and PLAYLIST_AUDIO_REPEAT_MODE_KEY")
+        val repeat = settings.getInt("audio_repeat_mode", -1)
+        if (repeat != -1) {
+            settings.putSingle("video_repeat_mode", repeat)
+        }
+    }
 }
\ No newline at end of file



More information about the Android mailing list