[Android] Add support for updating repeat and shuffle via media session callback

Robert Stone git at videolan.org
Mon Jan 10 07:06:59 UTC 2022


vlc-android | branch: master | Robert Stone <rhstone at gmail.com> | Fri Dec 31 23:34:35 2021 -0800| [2c44250b30323a58fda178c78a2f6d0332b9f88f] | committer: Nicolas Pomepuy

Add support for updating repeat and shuffle via media session callback

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

 .../src/org/videolan/vlc/MediaSessionCallback.kt          |  8 ++++++++
 .../vlc-android/src/org/videolan/vlc/PlaybackService.kt   | 15 ++++++++++++++-
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/application/vlc-android/src/org/videolan/vlc/MediaSessionCallback.kt b/application/vlc-android/src/org/videolan/vlc/MediaSessionCallback.kt
index 66ff9856f..516f96073 100644
--- a/application/vlc-android/src/org/videolan/vlc/MediaSessionCallback.kt
+++ b/application/vlc-android/src/org/videolan/vlc/MediaSessionCallback.kt
@@ -304,6 +304,14 @@ internal class MediaSessionCallback(private val playbackService: PlaybackService
         }
     }
 
+    override fun onSetShuffleMode(shuffleMode: Int) {
+        playbackService.shuffleType = shuffleMode
+    }
+
+    override fun onSetRepeatMode(repeatMode: Int) {
+        playbackService.repeatType = repeatMode
+    }
+
     override fun onPause() = playbackService.pause()
 
     override fun onStop() = playbackService.stop()
diff --git a/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt b/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt
index 9ccb7d527..2d7908624 100644
--- a/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt
+++ b/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt
@@ -268,12 +268,25 @@ class PlaybackService : MediaBrowserServiceCompat(), LifecycleOwner {
         @MainThread
         get() = playlistManager.shuffling
 
+    var shuffleType: Int
+        @MainThread
+        get() = if (playlistManager.shuffling) PlaybackStateCompat.SHUFFLE_MODE_ALL else PlaybackStateCompat.SHUFFLE_MODE_NONE
+        @MainThread
+        set(shuffleType) {
+            when {
+                shuffleType == PlaybackStateCompat.SHUFFLE_MODE_ALL && !isShuffling -> shuffle()
+                shuffleType == PlaybackStateCompat.SHUFFLE_MODE_NONE && isShuffling -> shuffle()
+                shuffleType == PlaybackStateCompat.SHUFFLE_MODE_GROUP && !isShuffling -> shuffle()
+                shuffleType == PlaybackStateCompat.SHUFFLE_MODE_GROUP && isShuffling -> publishState()
+            }
+        }
+
     var repeatType: Int
         @MainThread
         get() = playlistManager.repeating
         @MainThread
         set(repeatType) {
-            playlistManager.setRepeatType(repeatType)
+            playlistManager.setRepeatType(if (repeatType == PlaybackStateCompat.REPEAT_MODE_GROUP) PlaybackStateCompat.REPEAT_MODE_ALL else repeatType)
             publishState()
         }
 



More information about the Android mailing list