[Android] startService for remote MEDIA_PLAY(PAUSE) command

Geoffrey Métais git at videolan.org
Thu Dec 11 16:35:40 CET 2014


vlc-ports/android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Dec 11 15:53:44 2014 +0100| [a7a54d2201f9461b6106dbf0729a457ff42e1244] | committer: Geoffrey Métais

startService for remote MEDIA_PLAY(PAUSE) command

This will wake up VLC when controlled from remote controller.
Like Bluetooth a2dp device/remote contoller or smartwatches

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

 .../videolan/vlc/RemoteControlClientReceiver.java    |   18 ++++++++++++------
 .../src/org/videolan/vlc/audio/AudioService.java     |    8 +++++++-
 2 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/RemoteControlClientReceiver.java b/vlc-android/src/org/videolan/vlc/RemoteControlClientReceiver.java
index fe43fd9..8af007e 100644
--- a/vlc-android/src/org/videolan/vlc/RemoteControlClientReceiver.java
+++ b/vlc-android/src/org/videolan/vlc/RemoteControlClientReceiver.java
@@ -75,8 +75,7 @@ public class RemoteControlClientReceiver extends BroadcastReceiver {
                 case KeyEvent.KEYCODE_HEADSETHOOK:
                 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
                     long time = SystemClock.uptimeMillis();
-                    switch (event.getAction())
-                    {
+                    switch (event.getAction()) {
                         case KeyEvent.ACTION_DOWN:
                             if (event.getRepeatCount() > 0)
                                 break;
@@ -95,16 +94,23 @@ public class RemoteControlClientReceiver extends BroadcastReceiver {
                             else {
                                 if (mLibVLC.isPlaying())
                                     i = new Intent(AudioService.ACTION_REMOTE_PAUSE);
-                                else
-                                    i = new Intent(AudioService.ACTION_REMOTE_PLAY);
+                                else {
+                                    i = new Intent(context, AudioService.class);
+                                    i.setAction(AudioService.ACTION_REMOTE_PLAY);
+                                    context.startService(i);
+                                    mHeadsetUpTime = time;
+                                    return;
+                                }
                             }
                             mHeadsetUpTime = time;
                             break;
                     }
                     break;
                 case KeyEvent.KEYCODE_MEDIA_PLAY:
-                    i = new Intent(AudioService.ACTION_REMOTE_PLAY);
-                    break;
+                    i = new Intent(context, AudioService.class);
+                    i.setAction(AudioService.ACTION_REMOTE_PLAY);
+                    context.startService(i);
+                    return;
                 case KeyEvent.KEYCODE_MEDIA_PAUSE:
                     i = new Intent(AudioService.ACTION_REMOTE_PAUSE);
                     break;
diff --git a/vlc-android/src/org/videolan/vlc/audio/AudioService.java b/vlc-android/src/org/videolan/vlc/audio/AudioService.java
index 6fc79a0..b81526d 100644
--- a/vlc-android/src/org/videolan/vlc/audio/AudioService.java
+++ b/vlc-android/src/org/videolan/vlc/audio/AudioService.java
@@ -277,7 +277,13 @@ public class AudioService extends Service {
         if(ACTION_REMOTE_PLAYPAUSE.equals(intent.getAction())){
             if (hasCurrentMedia())
                 return START_STICKY;
-            else loadLastPlaylist();
+            else
+                loadLastPlaylist();
+        } else if (ACTION_REMOTE_PLAY.equals(intent.getAction())) {
+            if (hasCurrentMedia())
+                play();
+            else
+                loadLastPlaylist();
         }
         updateWidget(this);
         return super.onStartCommand(intent, flags, startId);



More information about the Android mailing list