Commit bff14226 authored by Alexandre Perraud's avatar Alexandre Perraud Committed by Geoffrey Métais
Browse files

Audio Streams : Display NowPlaying metadata



    fix #12815
Signed-off-by: default avatarGeoffrey Métais <geoffrey.metais@gmail.com>
parent 9ad222bf
......@@ -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;
}
......
......@@ -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));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment