[Android] Implement Scrobbling (close #11904)

Guillaume Hachez git at videolan.org
Fri Apr 10 10:16:09 CEST 2015


vlc-ports/android | branch: master | Guillaume Hachez <H.guillaume at gmail.com> | Wed Apr  8 20:01:49 2015 +0200| [cf99ad31d3543bc221044c0960bf3cdcc812fadc] | committer: Thomas Guillem

Implement Scrobbling (close #11904)

Signed-off-by: Thomas Guillem <thomas at gllm.fr>

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

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

diff --git a/vlc-android/src/org/videolan/vlc/audio/AudioService.java b/vlc-android/src/org/videolan/vlc/audio/AudioService.java
index 9c553fa..e70d325 100644
--- a/vlc-android/src/org/videolan/vlc/audio/AudioService.java
+++ b/vlc-android/src/org/videolan/vlc/audio/AudioService.java
@@ -843,6 +843,7 @@ public class AudioService extends Service {
         mHandler.removeMessages(SHOW_PROGRESS);
         // hideNotification(); <-- see event handler
         mLibVLC.pause();
+        broadcastMetadata();
     }
 
     private void play() {
@@ -852,6 +853,7 @@ public class AudioService extends Service {
             mHandler.sendEmptyMessage(SHOW_PROGRESS);
             showNotification();
             updateWidget(this);
+            broadcastMetadata();
         }
     }
 
@@ -864,6 +866,7 @@ public class AudioService extends Service {
         mPrevious.clear();
         mHandler.removeMessages(SHOW_PROGRESS);
         hideNotification();
+        broadcastMetadata();
         executeUpdate();
         executeUpdateProgress();
         changeAudioFocus(false);
@@ -952,6 +955,7 @@ public class AudioService extends Service {
         setUpRemoteControlClient();
         showNotification();
         updateWidget(this);
+        broadcastMetadata();
         updateRemoteControlClientMetadata();
         saveCurrentMedia();
 
@@ -1015,6 +1019,7 @@ public class AudioService extends Service {
         setUpRemoteControlClient();
         showNotification();
         updateWidget(this);
+        broadcastMetadata();
         updateRemoteControlClientMetadata();
         saveCurrentMedia();
 
@@ -1251,6 +1256,7 @@ public class AudioService extends Service {
             setUpRemoteControlClient();
             showNotification();
             updateWidget(AudioService.this);
+            broadcastMetadata();
             updateRemoteControlClientMetadata();
             AudioService.this.saveMediaList();
             AudioService.this.saveCurrentMedia();
@@ -1282,6 +1288,7 @@ public class AudioService extends Service {
             setUpRemoteControlClient();
             showNotification();
             updateWidget(AudioService.this);
+            broadcastMetadata();
             updateRemoteControlClientMetadata();
             determinePrevAndNextIndices();
         }
@@ -1502,6 +1509,23 @@ public class AudioService extends Service {
         sendBroadcast(i);
     }
 
+    private void broadcastMetadata() {
+        MediaWrapper media = getCurrentMedia();
+        if (media == null || media.getType() != MediaWrapper.TYPE_AUDIO)
+            return;
+
+        boolean playing = mLibVLC.isPlaying();
+
+        Intent broadcast = new Intent("com.android.music.metachanged");
+        broadcast.putExtra("track", media.getTitle());
+        broadcast.putExtra("artist", media.getArtist());
+        broadcast.putExtra("album", media.getAlbum());
+        broadcast.putExtra("duration", media.getLength());
+        broadcast.putExtra("playing", playing);
+
+        sendBroadcast(broadcast);
+    }
+
     private synchronized void loadLastPlaylist() {
         SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
         String currentMedia = prefs.getString("current_media", "");



More information about the Android mailing list