[Android] Reshuffle custom action order. Add new actions for rewind and fast forward.

Robert Stone git at videolan.org
Mon Sep 27 09:56:41 UTC 2021


vlc-android | branch: master | Robert Stone <rhstone at gmail.com> | Wed Sep 15 23:02:16 2021 -0700| [a082f45fcde9fd7a28f13cced6c89ded8b2b7036] | committer: Nicolas Pomepuy

Reshuffle custom action order. Add new actions for rewind and fast forward.

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

 .../src/org/videolan/vlc/MediaSessionCallback.kt            | 10 ++++++----
 .../vlc-android/src/org/videolan/vlc/PlaybackService.kt     | 13 +++++++------
 2 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/application/vlc-android/src/org/videolan/vlc/MediaSessionCallback.kt b/application/vlc-android/src/org/videolan/vlc/MediaSessionCallback.kt
index ad1e0b39c..6ba284254 100644
--- a/application/vlc-android/src/org/videolan/vlc/MediaSessionCallback.kt
+++ b/application/vlc-android/src/org/videolan/vlc/MediaSessionCallback.kt
@@ -106,10 +106,12 @@ internal class MediaSessionCallback(private val playbackService: PlaybackService
         return carMode && keyEvent.deviceId == 0 && (keyEvent.flags and KeyEvent.FLAG_KEEP_TOUCH_MODE != 0)
     }
 
-    override fun onCustomAction(action: String?, extras: Bundle?) {
-        when (action) {
-            "shuffle" -> playbackService.shuffle()
-            "repeat" -> playbackService.repeatType = when (playbackService.repeatType) {
+    override fun onCustomAction(actionId: String?, extras: Bundle?) {
+        when (actionId) {
+            "${BuildConfig.APP_ID}.rewind" -> onRewind()
+            "${BuildConfig.APP_ID}.fast_forward" -> onFastForward()
+            "${BuildConfig.APP_ID}.shuffle" -> playbackService.shuffle()
+            "${BuildConfig.APP_ID}.repeat" -> playbackService.repeatType = when (playbackService.repeatType) {
                 PlaybackStateCompat.REPEAT_MODE_NONE -> PlaybackStateCompat.REPEAT_MODE_ALL
                 PlaybackStateCompat.REPEAT_MODE_ALL -> PlaybackStateCompat.REPEAT_MODE_ONE
                 PlaybackStateCompat.REPEAT_MODE_ONE -> PlaybackStateCompat.REPEAT_MODE_NONE
diff --git a/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt b/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt
index 514e5cfd0..654e8e30b 100644
--- a/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt
+++ b/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt
@@ -959,8 +959,6 @@ class PlaybackService : MediaBrowserServiceCompat(), LifecycleOwner {
                         bob.putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, ctx.getBitmapFromDrawable(R.drawable.ic_no_media, 512, 512))
                 }
             }
-            bob.putLong("shuffle", 1L)
-            bob.putLong("repeat", repeatType.toLong())
             return at withContext bob.build()
         }
         if (this at PlaybackService::mediaSession.isInitialized) mediaSession.setMetadata(bob)
@@ -998,8 +996,6 @@ class PlaybackService : MediaBrowserServiceCompat(), LifecycleOwner {
             actions = actions or PlaybackStateCompat.ACTION_SKIP_TO_NEXT
         if (repeatType != PlaybackStateCompat.REPEAT_MODE_NONE || hasPrevious() || isSeekable)
             actions = actions or PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS
-        if (isSeekable)
-            actions = actions or PlaybackStateCompat.ACTION_FAST_FORWARD or PlaybackStateCompat.ACTION_REWIND or PlaybackStateCompat.ACTION_SEEK_TO
         if (playlistManager.canRepeat()) {
             actions = actions or PlaybackStateCompat.ACTION_SET_REPEAT_MODE
             val repeatResId = when (repeatType) {
@@ -1007,7 +1003,7 @@ class PlaybackService : MediaBrowserServiceCompat(), LifecycleOwner {
                 PlaybackStateCompat.REPEAT_MODE_ONE -> R.drawable.ic_auto_repeat_one_pressed
                 else -> R.drawable.ic_auto_repeat_normal
             }
-            pscb.addCustomAction("repeat", getString(R.string.repeat_title), repeatResId)
+            pscb.addCustomAction("${BuildConfig.APP_ID}.repeat", getString(R.string.repeat_title), repeatResId)
         }
         if (playlistManager.canShuffle()) {
             actions = actions or PlaybackStateCompat.ACTION_SET_SHUFFLE_MODE
@@ -1015,7 +1011,12 @@ class PlaybackService : MediaBrowserServiceCompat(), LifecycleOwner {
                 isShuffling -> R.drawable.ic_auto_shuffle_enabled
                 else -> R.drawable.ic_auto_shuffle_disabled
             }
-            pscb.addCustomAction("shuffle", getString(R.string.shuffle_title), shuffleResId)
+            pscb.addCustomAction("${BuildConfig.APP_ID}.shuffle", getString(R.string.shuffle_title), shuffleResId)
+        }
+        if (isSeekable) {
+            actions = actions or PlaybackStateCompat.ACTION_FAST_FORWARD or PlaybackStateCompat.ACTION_REWIND or PlaybackStateCompat.ACTION_SEEK_TO
+            pscb.addCustomAction("${BuildConfig.APP_ID}.rewind", getString(R.string.playback_rewind), R.drawable.ic_auto_rewind_10)
+            pscb.addCustomAction("${BuildConfig.APP_ID}.fast_forward", getString(R.string.playback_forward), R.drawable.ic_auto_forward_10)
         }
         pscb.setActions(actions)
         mediaSession.setRepeatMode(repeatType)



More information about the Android mailing list