Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I query the albums with MediaBrowser?

Tags:

android

media

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.

like image 395
Ukubu Avatar asked May 26 '16 12:05

Ukubu


2 Answers

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 see a clearer implementation of this in this sample.

like image 60
RominaV Avatar answered Oct 19 '22 23:10

RominaV


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)
like image 21
Mehta Avatar answered Oct 20 '22 00:10

Mehta