[Android] Better MediaSession initialization

Geoffrey Métais git at videolan.org
Thu Oct 29 12:04:23 CET 2015


vlc-ports/android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Oct 29 10:55:54 2015 +0100| [e51679f8852c7d7e6e2065b1133b5fd9639ed415] | committer: Geoffrey Métais

Better MediaSession initialization

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

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

diff --git a/vlc-android/src/org/videolan/vlc/PlaybackService.java b/vlc-android/src/org/videolan/vlc/PlaybackService.java
index 872cb6d..0ddd338 100644
--- a/vlc-android/src/org/videolan/vlc/PlaybackService.java
+++ b/vlc-android/src/org/videolan/vlc/PlaybackService.java
@@ -591,9 +591,6 @@ public class PlaybackService extends Service implements IVLCVout.Callback {
             switch (event.type) {
                 case MediaPlayer.Event.Playing:
 
-                    if (mMediaSession == null)
-                        initMediaSession(PlaybackService.this);
-
                     Log.i(TAG, "MediaPlayer.Event.Playing");
                     executeUpdate();
                     publishState(event.type);
@@ -674,6 +671,7 @@ public class PlaybackService extends Service implements IVLCVout.Callback {
                     if (event.getEsChangedType() == Media.Track.Type.Video) {
                         if (!handleVout()) {
                             /* Update notification content intent: resume video or resume audio activity */
+                            updateMetadata();
                             showNotification();
                         }
                     }
@@ -1071,14 +1069,14 @@ public class PlaybackService extends Service implements IVLCVout.Callback {
         }
     }
 
-    private void initMediaSession(Context context) {
+    private void initMediaSession() {
         mSessionCallback = new MediaSessionCallback();
-        mMediaSession = new MediaSessionCompat(context, "VLC");
+        mMediaSession = new MediaSessionCompat(this, "VLC");
         mMediaSession.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS
                 | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
         mMediaSession.setCallback(mSessionCallback);
-        updateMetadata();
     }
+
     private final class MediaSessionCallback extends MediaSessionCompat.Callback {
         @Override
         public void onPlay() {
@@ -1107,8 +1105,10 @@ public class PlaybackService extends Service implements IVLCVout.Callback {
 
     protected void updateMetadata() {
         MediaWrapper media = getCurrentMedia();
-        if (media == null || mMediaSession == null)
+        if (media == null)
             return;
+        if (mMediaSession == null)
+            initMediaSession();
         String title = media.getNowPlaying();
         if (title == null)
             title = media.getTitle();



More information about the Android mailing list