[Android] Remove RemoteControlClient

Geoffrey Métais git at videolan.org
Fri Nov 6 13:37:52 CET 2015


vlc-ports/android | branch: playlist | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Nov  6 13:11:45 2015 +0100| [f09b30ff0d7b7d626c26d17607196dbc8aed41da] | committer: Geoffrey Métais

Remove RemoteControlClient

It is useless now MediaSessionCompat does the job

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

 .../src/org/videolan/vlc/PlaybackService.java      |   61 --------------------
 1 file changed, 61 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/PlaybackService.java b/vlc-android/src/org/videolan/vlc/PlaybackService.java
index dd60a0d..d87f551 100644
--- a/vlc-android/src/org/videolan/vlc/PlaybackService.java
+++ b/vlc-android/src/org/videolan/vlc/PlaybackService.java
@@ -168,7 +168,6 @@ public class PlaybackService extends Service implements IVLCVout.Callback {
     /**
      * RemoteControlClient is for lock screen playback control.
      */
-    private RemoteControlClient mRemoteControlClient = null;
     private RemoteControlClientReceiver mRemoteControlClientReceiver = null;
     /**
      * Last widget position update timestamp
@@ -268,30 +267,6 @@ public class PlaybackService extends Service implements IVLCVout.Callback {
         }
     }
 
-    /**
-     * A function to control the Remote Control Client. It is needed for
-     * compatibility with devices below Ice Cream Sandwich (4.0).
-     *
-     * @param state Playback state
-     */
-    @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
-    private void setRemoteControlClientPlaybackState(int state) {
-        if (!AndroidUtil.isICSOrLater() || mRemoteControlClient == null)
-            return;
-
-        switch (state) {
-            case MediaPlayer.Event.Playing:
-                mRemoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING);
-                break;
-            case MediaPlayer.Event.Paused:
-                mRemoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PAUSED);
-                break;
-            case MediaPlayer.Event.Stopped:
-                mRemoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_STOPPED);
-                break;
-        }
-    }
-
     @Override
     public int onStartCommand(Intent intent, int flags, int startId) {
         if (intent == null)
@@ -396,32 +371,6 @@ public class PlaybackService extends Service implements IVLCVout.Callback {
         };
     }
 
-    /**
-     * Set up the remote control and tell the system we want to be the default receiver for the MEDIA buttons
-     */
-    @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
-    public void changeRemoteControlClient(AudioManager am, boolean acquire) {
-        if (acquire) {
-            Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
-            mediaButtonIntent.setComponent(mRemoteControlClientReceiverComponent);
-            PendingIntent mediaPendingIntent = PendingIntent.getBroadcast(this, 0, mediaButtonIntent, 0);
-
-            // create and register the remote control client
-            mRemoteControlClient = new RemoteControlClient(mediaPendingIntent);
-            am.registerRemoteControlClient(mRemoteControlClient);
-
-            mRemoteControlClient.setTransportControlFlags(
-                    RemoteControlClient.FLAG_KEY_MEDIA_PLAY |
-                            RemoteControlClient.FLAG_KEY_MEDIA_PAUSE |
-                            RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS |
-                            RemoteControlClient.FLAG_KEY_MEDIA_NEXT |
-                            RemoteControlClient.FLAG_KEY_MEDIA_STOP);
-        } else {
-            am.unregisterRemoteControlClient(mRemoteControlClient);
-            mRemoteControlClient = null;
-        }
-    }
-
     @TargetApi(Build.VERSION_CODES.FROYO)
     private void changeAudioFocusFroyoOrLater(boolean acquire) {
         final AudioManager am = (AudioManager)getSystemService(AUDIO_SERVICE);
@@ -434,9 +383,6 @@ public class PlaybackService extends Service implements IVLCVout.Callback {
                         AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
                 if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
                     am.setParameters("bgm_state=true");
-                    am.registerMediaButtonEventReceiver(mRemoteControlClientReceiverComponent);
-                    if (AndroidUtil.isICSOrLater())
-                        changeRemoteControlClient(am, acquire);
                     mHasAudioFocus = true;
                 }
             }
@@ -444,9 +390,6 @@ public class PlaybackService extends Service implements IVLCVout.Callback {
             if (mHasAudioFocus) {
                 final int result = am.abandonAudioFocus(mAudioFocusListener);
                 am.setParameters("bgm_state=false");
-                am.unregisterMediaButtonEventReceiver(mRemoteControlClientReceiverComponent);
-                if (AndroidUtil.isICSOrLater())
-                    changeRemoteControlClient(am, acquire);
                 mHasAudioFocus = false;
             }
         }
@@ -625,7 +568,6 @@ public class PlaybackService extends Service implements IVLCVout.Callback {
                     }
 
                     changeAudioFocus(true);
-                    setRemoteControlClientPlaybackState(event.type);
                     showNotification();
                     if (!mWakeLock.isHeld())
                         mWakeLock.acquire();
@@ -636,7 +578,6 @@ public class PlaybackService extends Service implements IVLCVout.Callback {
                     publishState(event.type);
                     executeUpdateProgress();
                     showNotification();
-                    setRemoteControlClientPlaybackState(event.type);
                     if (mWakeLock.isHeld())
                         mWakeLock.release();
                     break;
@@ -645,7 +586,6 @@ public class PlaybackService extends Service implements IVLCVout.Callback {
                     executeUpdate();
                     publishState(event.type);
                     executeUpdateProgress();
-                    setRemoteControlClientPlaybackState(event.type);
                     if (mWakeLock.isHeld())
                         mWakeLock.release();
                     changeAudioFocus(false);
@@ -1007,7 +947,6 @@ public class PlaybackService extends Service implements IVLCVout.Callback {
             media.release();
         }
         mMediaList.removeEventListener(mListEventListener);
-        setRemoteControlClientPlaybackState(MediaPlayer.Event.Stopped);
         mCurrentIndex = -1;
         mPrevious.clear();
         mHandler.removeMessages(SHOW_PROGRESS);



More information about the Android mailing list