[Android] Set initial playback state and allowed actions

Robert Stone git at videolan.org
Mon Dec 13 07:20:18 UTC 2021


vlc-android | branch: master | Robert Stone <rhstone at gmail.com> | Sun Dec  5 22:34:25 2021 -0800| [771072c63b1a34f95fbc4695164328ee0ec48e82] | committer: Nicolas Pomepuy

Set initial playback state and allowed actions

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

 .../vlc-android/src/org/videolan/vlc/PlaybackService.kt     | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt b/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt
index eddcbc7b4..72e6fb4a6 100644
--- a/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt
+++ b/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt
@@ -891,10 +891,15 @@ class PlaybackService : MediaBrowserServiceCompat(), LifecycleOwner {
         mediaButtonIntent.setClass(this, MediaButtonReceiver::class.java)
         val mbrIntent = PendingIntent.getBroadcast(this, 0, mediaButtonIntent, 0)
         val mbrName = ComponentName(this, MediaButtonReceiver::class.java)
-
-        mediaSession = MediaSessionCompat(this, "VLC", mbrName, mbrIntent)
-        mediaSession.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS or MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS)
-        mediaSession.setCallback(MediaSessionCallback(this))
+        val playbackState = PlaybackStateCompat.Builder()
+                .setActions(enabledActions)
+                .setState(PlaybackStateCompat.STATE_NONE, 0, 0f)
+                .build()
+        mediaSession = MediaSessionCompat(this, "VLC", mbrName, mbrIntent).apply {
+            setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS or MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS)
+            setCallback(MediaSessionCallback(this at PlaybackService))
+            setPlaybackState(playbackState)
+        }
         try {
             mediaSession.isActive = true
         } catch (e: NullPointerException) {



More information about the Android mailing list