[Android] [PATCH] startService for remote MEDIA_PLAY command

Geoffrey Métais geoffrey.metais at gmail.com
Thu Dec 11 15:55:55 CET 2014


This will wake up VLC when controlled from remote controller.
Like Bluetooth a2dp device/remote contoller or smartwatches
---
 .../src/org/videolan/vlc/RemoteControlClientReceiver.java        | 9 +++++----
 vlc-android/src/org/videolan/vlc/audio/AudioService.java         | 8 +++++++-
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/RemoteControlClientReceiver.java b/vlc-android/src/org/videolan/vlc/RemoteControlClientReceiver.java
index fe43fd9..b493cc6 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;
@@ -103,8 +102,10 @@ public class RemoteControlClientReceiver extends BroadcastReceiver {
                     }
                     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);
-- 
1.9.1



More information about the Android mailing list