I guess it has to do something with the onLoadChildren method, but I have no idea how to get the albums, song or artists via MediaBrowser.
If you already have a service that extends MediaBrowserService
, you can retrieve any metadata in onLoadChildren
.
In your onLoadChildren you should use MediaMetadata
:
Contains metadata about an item, such as the title, artist, etc.
From which you can retrieve things like artist, title, etc, using MediaDescription
:
A simple set of metadata for a media item suitable for display.
@Override
public void onLoadChildren(final String parentMediaId, final Result<List<MediaItem>> result) {
for (MediaMetadata track : mMusicProvider.getMusicsByGenre(genre)) {
// once you have an instance of MediaMetadata, you can retrieve any data you want:
MediaDescription simpleData = track.getDescription();
// or retrieving with a key from its info Bundle:
// android.media.metadata.MEDIA_ID
// android.media.metadata.TRACK_NUMBER
// android.media.metadata.ALBUM
// android.media.metadata.GENRE
// android.media.metadata.TITLE
// android.media.metadata.ARTIST
// android.media.metadata.NUM_TRACKS
// android.media.metadata.DURATION
// android.media.metadata.ALBUM_ART_URI
track.getString( ... );
}
}
You can use MediaMetadataRetriever to retrieve detail from media file
For Example:
MediaMetadataRetriever metaRetriver = new MediaMetadataRetriever();
metaRetriver.setDataSource("/sdcard/audio.mp3");
String artist= metaRetriver .extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST);
Strng genre = metaRetriver .extractMetadata(MediaMetadataRetriever.METADATA_KEY_GENRE)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With