[Android] Init MediaSession with KitKat bug workaround

Geoffrey Métais git at videolan.org
Thu Nov 12 14:53:54 CET 2015


vlc-ports/android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Nov 12 14:52:24 2015 +0100| [2747285fbcfd0b012ca0cde9ebc423759efb8006] | committer: Geoffrey Métais

Init MediaSession with KitKat bug workaround

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=2747285fbcfd0b012ca0cde9ebc423759efb8006
---

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

diff --git a/vlc-android/src/org/videolan/vlc/PlaybackService.java b/vlc-android/src/org/videolan/vlc/PlaybackService.java
index 7b094c6..d0f2127 100644
--- a/vlc-android/src/org/videolan/vlc/PlaybackService.java
+++ b/vlc-android/src/org/videolan/vlc/PlaybackService.java
@@ -1007,6 +1007,18 @@ public class PlaybackService extends Service implements IVLCVout.Callback {
         mMediaSession.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS
                 | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
         mMediaSession.setCallback(mSessionCallback);
+        try {
+            mMediaSession.setActive(true);
+        } catch (NullPointerException e) {
+            // Some versions of KitKat do not support AudioManager.registerMediaButtonIntent
+            // with a PendingIntent. They will throw a NullPointerException, in which case
+            // they should be able to activate a MediaSessionCompat with only transport
+            // controls.
+            mMediaSession.setActive(false);
+            mMediaSession.setFlags(MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
+            mMediaSession.setActive(true);
+
+        }
     }
 
     private final class MediaSessionCallback extends MediaSessionCompat.Callback {



More information about the Android mailing list