[Android] Audio Streams : Display NowPlaying metadata
Alexandre Perraud
git at videolan.org
Thu Nov 27 11:18:54 CET 2014
vlc-ports/android | branch: master | Alexandre Perraud <4leyx4ndre at gmail.com> | Tue Nov 25 16:56:32 2014 +0100| [bff1422679545d101d7a1a2965ffdc137b442202] | committer: Geoffrey Métais
Audio Streams : Display NowPlaying metadata
fix #12815
Signed-off-by: Geoffrey Métais <geoffrey.metais at gmail.com>
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=bff1422679545d101d7a1a2965ffdc137b442202
---
libvlc/src/org/videolan/libvlc/Media.java | 47 ++++++++++++++++++--
.../src/org/videolan/vlc/audio/AudioService.java | 32 ++++++++++---
2 files changed, 71 insertions(+), 8 deletions(-)
diff --git a/libvlc/src/org/videolan/libvlc/Media.java b/libvlc/src/org/videolan/libvlc/Media.java
index 5f10054..eb556a9 100644
--- a/libvlc/src/org/videolan/libvlc/Media.java
+++ b/libvlc/src/org/videolan/libvlc/Media.java
@@ -111,6 +111,30 @@ public class Media implements Comparable<Media> {
private String mTrackID;
private String mArtworkURL;
+ public final static int libvlc_meta_Title = 0;
+ public final static int libvlc_meta_Artist = 1;
+ public final static int libvlc_meta_Genre = 2;
+// public final static int libvlc_meta_Copyright = 3;
+ public final static int libvlc_meta_Album = 4;
+// public final static int libvlc_meta_TrackNumber = 5;
+// public final static int libvlc_meta_Description = 6;
+// public final static int libvlc_meta_Rating = 7;
+// public final static int libvlc_meta_Date = 8;
+// public final static int libvlc_meta_Setting = 9;
+// public final static int libvlc_meta_URL = 10;
+// public final static int libvlc_meta_Language = 11;
+ public final static int libvlc_meta_NowPlaying = 12;
+// public final static int libvlc_meta_Publisher = 13;
+// public final static int libvlc_meta_EncodedBy = 14;
+ public final static int libvlc_meta_ArtworkURL = 15;
+// public final static int libvlc_meta_TrackID = 16;
+// public final static int libvlc_meta_TrackTotal = 17;
+// public final static int libvlc_meta_Director = 18;
+// public final static int libvlc_meta_Season = 19;
+// public final static int libvlc_meta_Episode = 20;
+// public final static int libvlc_meta_ShowName = 21;
+// public final static int libvlc_meta_Actors = 22;
+
private final String mLocation;
private String mFilename;
private long mTime = 0;
@@ -271,8 +295,13 @@ public class Media implements Comparable<Media> {
return mLocation;
}
- public void updateMeta() {
-
+ public void updateMeta(LibVLC libVLC) {
+ mTitle = libVLC.getMeta(libvlc_meta_Title);
+ mArtist = getValueWrapper(libVLC.getMeta(libvlc_meta_Artist), UnknownStringType.Artist);
+ mGenre = getValueWrapper(libVLC.getMeta(libvlc_meta_Genre), UnknownStringType.Genre);
+ mAlbum = getValueWrapper(libVLC.getMeta(libvlc_meta_Album), UnknownStringType.Album);
+ mNowPlaying = libVLC.getMeta(libvlc_meta_NowPlaying);
+ mArtworkURL = libVLC.getMeta(libvlc_meta_ArtworkURL);
}
public String getFileName() {
@@ -368,13 +397,21 @@ public class Media implements Comparable<Media> {
}
public String getSubtitle() {
- return mType != TYPE_VIDEO ? mArtist + " - " + mAlbum : "";
+ return mType != TYPE_VIDEO ?
+ mNowPlaying != null ?
+ mNowPlaying
+ : mArtist + " - " + mAlbum
+ : "";
}
public String getArtist() {
return mArtist;
}
+ public Boolean isArtistUnknown() {
+ return (mArtist.equals(getValueWrapper(null, UnknownStringType.Artist)));
+ }
+
public String getGenre() {
if(getValueWrapper(null, UnknownStringType.Genre).equals(mGenre))
return mGenre;
@@ -392,6 +429,10 @@ public class Media implements Comparable<Media> {
return mAlbum;
}
+ public Boolean isAlbumUnknown() {
+ return (mAlbum.equals(getValueWrapper(null, UnknownStringType.Album)));
+ }
+
public String getTrackNumber() {
return mTrackNumber;
}
diff --git a/vlc-android/src/org/videolan/vlc/audio/AudioService.java b/vlc-android/src/org/videolan/vlc/audio/AudioService.java
index bf4e85f..c33abc8 100644
--- a/vlc-android/src/org/videolan/vlc/audio/AudioService.java
+++ b/vlc-android/src/org/videolan/vlc/audio/AudioService.java
@@ -524,6 +524,13 @@ public class AudioService extends Service {
case EventHandler.MediaPlayerTimeChanged:
// avoid useless error logs
break;
+ case EventHandler.MediaMetaChanged:
+ service.getCurrentMedia().updateMeta(service.mLibVLC);
+ service.setUpRemoteControlClient();
+ service.executeUpdate();
+ service.showNotification();
+ service.updateRemoteControlClientMetadata();
+ break;
default:
Log.e(TAG, String.format("Event not handled (0x%x)", msg.getData().getInt("event")));
break;
@@ -712,6 +719,11 @@ public class AudioService extends Service {
String album = media.getAlbum();
Notification notification;
+ if (media.isArtistUnknown() && media.isAlbumUnknown() && media.getNowPlaying() != null) {
+ artist = media.getNowPlaying();
+ album = "";
+ }
+
// add notification to status bar
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_stat_vlc)
@@ -920,9 +932,15 @@ public class AudioService extends Service {
Media media = getCurrentMedia();
if (mRemoteControlClient != null && media != null) {
MetadataEditor editor = mRemoteControlClient.editMetadata(true);
- editor.putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, media.getAlbum());
- editor.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, media.getArtist());
- editor.putString(MediaMetadataRetriever.METADATA_KEY_ALBUMARTIST, media.getArtist());
+ if (media.getNowPlaying() != null) {
+ editor.putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, "");
+ editor.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, "");
+ editor.putString(MediaMetadataRetriever.METADATA_KEY_ALBUMARTIST, media.getNowPlaying());
+ } else {
+ editor.putString(MediaMetadataRetriever.METADATA_KEY_ALBUMARTIST, "");
+ editor.putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, media.getAlbum());
+ editor.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, media.getArtist());
+ }
editor.putString(MediaMetadataRetriever.METADATA_KEY_GENRE, media.getGenre());
editor.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, media.getTitle());
editor.putLong(MediaMetadataRetriever.METADATA_KEY_DURATION, media.getLength());
@@ -1022,7 +1040,9 @@ public class AudioService extends Service {
@Override
public String getArtist() throws RemoteException {
if (hasCurrentMedia())
- return getCurrentMedia().getArtist();
+ return getCurrentMedia().isArtistUnknown() && getCurrentMedia().getNowPlaying() != null ?
+ getCurrentMedia().getNowPlaying()
+ : getCurrentMedia().getArtist();
else
return null;
}
@@ -1368,7 +1388,9 @@ public class AudioService extends Service {
if (hasCurrentMedia()) {
i.putExtra("title", getCurrentMedia().getTitle());
- i.putExtra("artist", getCurrentMedia().getArtist());
+ i.putExtra("artist", getCurrentMedia().isArtistUnknown() && getCurrentMedia().getNowPlaying() != null ?
+ getCurrentMedia().getNowPlaying()
+ : getCurrentMedia().getArtist());
}
else {
i.putExtra("title", context.getString(R.string.widget_name));
More information about the Android
mailing list