MediaMetadata

public final class MediaMetadata
extends Object implements VersionedParcelable

java.lang.Object
   ↳ androidx.media2.common.MediaMetadata


Contains metadata about an item, such as the title, artist, etc. This is optional, but you'd better to provide this as much as possible when you're using media widget and/or session APIs.

The media widget components build its UI based on the metadata here. For an example, MediaControlView will show title from the metadata.

The MediaLibraryService.MediaLibrarySession would require some metadata values when it provides MediaItems to MediaBrowser.

Topics covered here:

  1. Media ID
  2. Browsable type
  3. Playable
  4. Duration
  5. User rating

Media ID

If set, the media ID must be the persistent key for the underlying media contents, so MediaController and MediaBrowser can store the information and reuse it later. Some APIs requires a media ID (e.g. MediaController.setRating(String, Rating), so you'd better specify one.

Typical example of using media ID is the URI of the contents, but use it with the caution because the metadata is shared across the process in plain text.

The MediaLibraryService.MediaLibrarySession would require it for the library root, so MediaBrowser can call subsequent MediaBrowser.getChildren(String, int, int, MediaLibraryService.LibraryParams) with the ID.

Browsable type

Browsable defines whether the media item has children and type of children if any. With this, MediaBrowser can know whether the subsequent MediaBrowser.getChildren(String, int, int, MediaLibraryService.LibraryParams) would successfully run.

The MediaLibraryService.MediaLibrarySession would require the explicit browsable type for the media items returned by the MediaLibraryService.MediaLibrarySession.MediaLibrarySessionCallback.

Playable type

Playable defines whether the media item can be played or not. It may be possible for a playlist to contain a media item which isn't playable in order to show a disabled media item.

The MediaLibraryService.MediaLibrarySession would require the explicit playable value for the media items returned by the MediaLibraryService.MediaLibrarySession.MediaLibrarySessionCallback.

Duration

The duration is the length of the contents. The MediaController can only get the duration through the metadata. This tells when would the playback ends, and also tells about the allowed range of MediaController.seekTo(long).

If it's not set by developer, MediaSession would update the duration in the metadata with the SessionPlayer.getDuration().

User rating

Prefer to have unrated user rating instead of null, so MediaController can know the possible user rating type for calling MediaController.setRating(String, Rating).

Summary

Nested classes

class MediaMetadata.Builder

Use to build MediaMetadatax objects. 

Constants

long BROWSABLE_TYPE_ALBUMS

The type of browsable that contains browsable items categorized by album.

long BROWSABLE_TYPE_ARTISTS

The type of browsable that contains browsable items categorized by artist.

long BROWSABLE_TYPE_GENRES

The type of browsable that contains browsable items categorized by genre.

long BROWSABLE_TYPE_MIXED

The type of browsable that is unknown or contains media items of mixed types.

long BROWSABLE_TYPE_NONE

The type of browsable for non-browsable media item.

long BROWSABLE_TYPE_PLAYLISTS

The type of browsable that contains browsable items categorized by playlist.

long BROWSABLE_TYPE_TITLES

The type of browsable that only contains playable media items.

long BROWSABLE_TYPE_YEARS

The type of browsable that contains browsable items categorized by year.

String METADATA_KEY_ADVERTISEMENT

The metadata key for a Long typed value to retrieve the information about whether the media is an advertisement.

String METADATA_KEY_ALBUM

The metadata key for a CharSequence or String typed value to retrieve the information about the album title for the media.

String METADATA_KEY_ALBUM_ART

The metadata key for a Bitmap typed value to retrieve the information about the artwork for the album of the media's original source.

String METADATA_KEY_ALBUM_ARTIST

The metadata key for a CharSequence or String typed value to retrieve the information about the artist for the album of the media's original source.

String METADATA_KEY_ALBUM_ART_URI

The metadata key for a CharSequence or String typed value to retrieve the information about the Uri of the artwork for the album of the media's original source.

String METADATA_KEY_ART

The metadata key for a Bitmap typed value to retrieve the information about the artwork for the media.

String METADATA_KEY_ARTIST

The metadata key for a CharSequence or String typed value to retrieve the information about the artist of the media.

String METADATA_KEY_ART_URI

The metadata key for a CharSequence or String typed value to retrieve the information about Uri of the artwork for the media.

String METADATA_KEY_AUTHOR

The metadata key for a CharSequence or String typed value to retrieve the information about the author of the media.

String METADATA_KEY_BROWSABLE

The metadata key for a Long typed value to retrieve the information about the type of browsable.

String METADATA_KEY_COMPILATION

The metadata key for a CharSequence or String typed value to retrieve the information about the compilation status of the media.

String METADATA_KEY_COMPOSER

The metadata key for a CharSequence or String typed value to retrieve the information about the composer of the media.

String METADATA_KEY_DATE

The metadata key for a CharSequence or String typed value to retrieve the information about the date the media was created or published.