[Android] Set pendingIntent for remote control receiver

Geoffrey Métais git at videolan.org
Fri Dec 23 13:36:59 CET 2016


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Dec 23 13:33:42 2016 +0100| [4326ce8e32be8bb02e0d5b881337b773c325f8e2] | committer: Geoffrey Métais

Set pendingIntent for remote control receiver

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

 vlc-android/src/org/videolan/vlc/PlaybackService.java | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/PlaybackService.java b/vlc-android/src/org/videolan/vlc/PlaybackService.java
index 4bba595..72cd04a 100644
--- a/vlc-android/src/org/videolan/vlc/PlaybackService.java
+++ b/vlc-android/src/org/videolan/vlc/PlaybackService.java
@@ -54,6 +54,7 @@ import android.support.v4.media.MediaBrowserCompat;
 import android.support.v4.media.MediaBrowserServiceCompat;
 import android.support.v4.media.MediaDescriptionCompat;
 import android.support.v4.media.MediaMetadataCompat;
+import android.support.v4.media.session.MediaButtonReceiver;
 import android.support.v4.media.session.MediaSessionCompat;
 import android.support.v4.media.session.PlaybackStateCompat;
 import android.support.v7.app.NotificationCompat;
@@ -74,7 +75,6 @@ import org.videolan.medialibrary.media.MediaWrapper;
 import org.videolan.vlc.gui.AudioPlayerContainerActivity;
 import org.videolan.vlc.gui.helpers.AudioUtil;
 import org.videolan.vlc.gui.helpers.BitmapUtil;
-import org.videolan.vlc.gui.helpers.UiTools;
 import org.videolan.vlc.gui.preferences.PreferencesActivity;
 import org.videolan.vlc.gui.preferences.PreferencesFragment;
 import org.videolan.vlc.gui.video.PopupManager;
@@ -1016,13 +1016,17 @@ public class PlaybackService extends MediaBrowserServiceCompat implements IVLCVo
     }
 
     private void initMediaSession() {
-         ComponentName mediaButtonEventReceiver = new ComponentName(this,
-                    RemoteControlClientReceiver.class);
+        Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
+
+        mediaButtonIntent.setClass(this, MediaButtonReceiver.class);
+        PendingIntent mbrIntent = PendingIntent.getBroadcast(this, 0, mediaButtonIntent, 0);
+
         mSessionCallback = new MediaSessionCallback();
-        mMediaSession = new MediaSessionCompat(this, "VLC", mediaButtonEventReceiver, null);
+        mMediaSession = new MediaSessionCompat(this, "VLC");
         mMediaSession.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS
                 | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
         mMediaSession.setCallback(mSessionCallback);
+        mMediaSession.setMediaButtonReceiver(mbrIntent);
         try {
             mMediaSession.setActive(true);
             setSessionToken(mMediaSession.getSessionToken());



More information about the Android mailing list