[Android] Send media metadata to Pebble smartwatches

Geoffrey Métais git at videolan.org
Wed Dec 10 14:40:16 CET 2014


vlc-ports/android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Dec 10 13:39:55 2014 +0100| [b7fee523ad4497d09b2dfd155b1d0c2236f63994] | committer: Geoffrey Métais

Send media metadata to Pebble smartwatches

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

 .../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() {



More information about the Android mailing list