[Android] Mediasession: Add repeat and shuffle states

Geoffrey Métais git at videolan.org
Tue Dec 24 12:12:05 CET 2019


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Dec 23 18:10:39 2019 +0100| [96d65ce13154a93173d1737e2c38f08725367608] | committer: Geoffrey Métais

Mediasession: Add repeat and shuffle states

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

 vlc-android/src/org/videolan/vlc/PlaybackService.kt | 4 ++++
 vlc-android/src/org/videolan/vlc/util/Constants.kt  | 8 +++++---
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/PlaybackService.kt b/vlc-android/src/org/videolan/vlc/PlaybackService.kt
index 600a84f16..9f5339b08 100644
--- a/vlc-android/src/org/videolan/vlc/PlaybackService.kt
+++ b/vlc-android/src/org/videolan/vlc/PlaybackService.kt
@@ -878,7 +878,11 @@ class PlaybackService : MediaBrowserServiceCompat(), LifecycleOwner {
         if (isSeekable)
             actions = actions or PlaybackStateCompat.ACTION_FAST_FORWARD or PlaybackStateCompat.ACTION_REWIND or PlaybackStateCompat.ACTION_SEEK_TO
         actions = actions or PlaybackStateCompat.ACTION_SKIP_TO_QUEUE_ITEM
+        if (playlistManager.hasPlaylist()) actions = actions or PlaybackStateCompat.ACTION_SET_SHUFFLE_MODE
+        actions = actions or PlaybackStateCompat.ACTION_SET_REPEAT_MODE
         pscb.setActions(actions)
+        mediaSession.setRepeatMode(repeatType)
+        mediaSession.setShuffleMode(if (isShuffling) PlaybackStateCompat.SHUFFLE_MODE_ALL else PlaybackStateCompat.SHUFFLE_MODE_NONE)
         val repeatResId = if (repeatType == REPEAT_ALL) R.drawable.ic_auto_repeat_pressed else if (repeatType == REPEAT_ONE) R.drawable.ic_auto_repeat_one_pressed else R.drawable.ic_auto_repeat_normal
         if (playlistManager.hasPlaylist())
             pscb.addCustomAction("shuffle", getString(R.string.shuffle_title), if (isShuffling) R.drawable.ic_auto_shuffle_pressed else R.drawable.ic_auto_shuffle_normal)
diff --git a/vlc-android/src/org/videolan/vlc/util/Constants.kt b/vlc-android/src/org/videolan/vlc/util/Constants.kt
index aae743ea1..7f60219aa 100644
--- a/vlc-android/src/org/videolan/vlc/util/Constants.kt
+++ b/vlc-android/src/org/videolan/vlc/util/Constants.kt
@@ -21,6 +21,8 @@
 @file:JvmName("Constants")
 package org.videolan.vlc.util
 
+import android.support.v4.media.session.PlaybackStateCompat
+
 // StartActivity
 const val PREF_FIRST_RUN = "first_run"
 const val EXTRA_FIRST_RUN = "extra_first_run"
@@ -58,9 +60,9 @@ val ACTION_REMOTE_GENERIC = "remote.".buildPkgString()
 const val ACTION_CAR_MODE_EXIT = "android.app.action.EXIT_CAR_MODE"
 const val PLAYLIST_TYPE_AUDIO = 0
 const val PLAYLIST_TYPE_VIDEO = 1
-const val REPEAT_NONE = 0
-const val REPEAT_ONE = 1
-const val REPEAT_ALL = 2
+const val REPEAT_NONE = PlaybackStateCompat.REPEAT_MODE_NONE
+const val REPEAT_ONE = PlaybackStateCompat.REPEAT_MODE_ONE
+const val REPEAT_ALL = PlaybackStateCompat.REPEAT_MODE_ALL
 const val MEDIALIBRARY_PAGE_SIZE = 500
 
 // MediaParsingService



More information about the Android mailing list