[vlc-devel] [PATCH] [Android] Implement Scrobbling compatibility (#11904)
Guillaume
h.guillaume at gmail.com
Thu Apr 9 10:41:16 CEST 2015
Thanks for your insights. I made the following changes:
* If the media type isn't audio, the method is aborted.
* It's no longer using the Util methods, as Thomas recommended.
* The method doesn't require a Context argument anymore, since the service
itself is a Context.
As the developer of a GPL app that scrobbles songs (QuickLyric on Github),
I assure you that the broadcast should really be sent no matter what, even
if all fields are null. It's how all music players do it.
Here's the updated patch:
>From 23d3b82a79c5fef49f9d4e561d1bb028779f0401 Mon Sep 17 00:00:00 2001
From: Guillaume Hachez <H.guillaume at gmail.com>
Date: Wed, 8 Apr 2015 20:01:49 +0200
Subject: [PATCH 1/1] Implement Scrobbling (close #11904)
---
.../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 090ef6f..83e6c48 100644
--- a/vlc-android/src/org/videolan/vlc/audio/AudioService.java
+++ b/vlc-android/src/org/videolan/vlc/audio/AudioService.java
@@ -819,6 +819,7 @@ public class AudioService extends Service {
mHandler.removeMessages(SHOW_PROGRESS);
// hideNotification(); <-- see event handler
mLibVLC.pause();
+ broadcastMetadata();
}
private void play() {
@@ -828,6 +829,7 @@ public class AudioService extends Service {
mHandler.sendEmptyMessage(SHOW_PROGRESS);
showNotification();
updateWidget(this);
+ broadcastMetadata();
}
}
@@ -840,6 +842,7 @@ public class AudioService extends Service {
mPrevious.clear();
mHandler.removeMessages(SHOW_PROGRESS);
hideNotification();
+ broadcastMetadata();
executeUpdate();
executeUpdateProgress();
changeAudioFocus(false);
@@ -928,6 +931,7 @@ public class AudioService extends Service {
setUpRemoteControlClient();
showNotification();
updateWidget(this);
+ broadcastMetadata();
updateRemoteControlClientMetadata();
saveCurrentMedia();
@@ -991,6 +995,7 @@ public class AudioService extends Service {
setUpRemoteControlClient();
showNotification();
updateWidget(this);
+ broadcastMetadata();
updateRemoteControlClientMetadata();
saveCurrentMedia();
@@ -1227,6 +1232,7 @@ public class AudioService extends Service {
setUpRemoteControlClient();
showNotification();
updateWidget(AudioService.this);
+ broadcastMetadata();
updateRemoteControlClientMetadata();
AudioService.this.saveMediaList();
AudioService.this.saveCurrentMedia();
@@ -1258,6 +1264,7 @@ public class AudioService extends Service {
setUpRemoteControlClient();
showNotification();
updateWidget(AudioService.this);
+ broadcastMetadata();
updateRemoteControlClientMetadata();
determinePrevAndNextIndices();
}
@@ -1478,6 +1485,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", "");
--
2.3.5
On Thu, Apr 9, 2015 at 9:08 AM Jean-Baptiste Kempf <jb at videolan.org> wrote:
> On 08 Apr, Guillaume wrote :
> > This is AudioService.java. I just assumed it was only used for audio
> media
> > files. Is this wrong? In my testing, it hasn't triggered when playing
> video
> > files.
>
> Yes, this is a wrong assumption. It will be moved to play everything.
>
> With my kindest regards,
>
> --
> Jean-Baptiste Kempf
> http://www.jbkempf.com/ - +33 672 704 734
> Sent from my Electronic Device
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20150409/ca373541/attachment.html>
More information about the vlc-devel
mailing list