[Android] [PATCH] Send media metadata to Pebble smartwatches

Geoffrey Métais geoffrey.metais at gmail.com
Wed Dec 10 13:40:40 CET 2014


---
 .../src/org/videolan/vlc/audio/AudioService.java        | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/vlc-android/src/org/videolan/vlc/audio/AudioService.java b/vlc-android/src/org/videolan/vlc/audio/AudioService.java
index c33abc8..6fc79a0 100644
--- a/vlc-android/src/org/videolan/vlc/audio/AudioService.java
+++ b/vlc-android/src/org/videolan/vlc/audio/AudioService.java
@@ -67,6 +67,7 @@ import android.content.Context;
 import android.content.Intent;
 import android.content.IntentFilter;
 import android.content.SharedPreferences;
+import android.content.pm.PackageManager;
 import android.graphics.Bitmap;
 import android.media.AudioManager;
 import android.media.AudioManager.OnAudioFocusChangeListener;
@@ -119,6 +120,7 @@ public class AudioService extends Service {
     private EventHandler mEventHandler;
     private OnAudioFocusChangeListener audioFocusListener;
     private boolean mDetectHeadset = true;
+    private boolean mPebbleEnabled;
     private PowerManager.WakeLock mWakeLock;
 
     private static boolean mWasPlayingAudio = false;
@@ -203,6 +205,12 @@ public class AudioService extends Service {
             mRemoteControlClientReceiver = new RemoteControlClientReceiver();
             registerReceiver(mRemoteControlClientReceiver, filter);
         }
+        try {
+            getPackageManager().getPackageInfo("com.getpebble.android", PackageManager.GET_ACTIVITIES);
+            mPebbleEnabled = true;
+        } catch (PackageManager.NameNotFoundException e) {
+            mPebbleEnabled = false;
+        }
     }
 
     /**
@@ -949,6 +957,15 @@ public class AudioService extends Service {
             editor.putBitmap(MetadataEditor.BITMAP_KEY_ARTWORK, ((cover != null) ? cover.copy(cover.getConfig(), false) : null));
             editor.apply();
         }
+
+        //Send metadata to Pebble watch
+        if (mPebbleEnabled) {
+            final Intent i = new Intent("com.getpebble.action.NOW_PLAYING");
+            i.putExtra("artist", media.getArtist());
+            i.putExtra("album", media.getAlbum());
+            i.putExtra("track", media.getTitle());
+            sendBroadcast(i);
+        }
     }
 
     private void previous() {
-- 
1.9.1



More information about the Android mailing list