MediaMetadata
class MediaMetadata : CustomVersionedParcelable
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, androidx.media2.widget.MediaControlView
will show title from the metadata.
The androidx.media2.session.MediaLibraryService.MediaLibrarySession
would require some metadata values when it provides MediaItem
s to androidx.media2.session.MediaBrowser
.
Topics covered here:
Media ID
If set, the media ID must be the persistent key for the underlying media contents, so androidx.media2.session.MediaController
and androidx.media2.session.MediaBrowser
can store the information and reuse it later. Some APIs requires a media ID (e.g. androidx.media2.session.MediaController#setRating
, 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 androidx.media2.session.MediaLibraryService.MediaLibrarySession
would require it for the library root, so androidx.media2.session.MediaBrowser
can call subsequent androidx.media2.session.MediaBrowser#getChildren
with the ID.
Browsable type
Browsable defines whether the media item has children and type of children if any. With this, androidx.media2.session.MediaBrowser
can know whether the subsequent androidx.media2.session.MediaBrowser#getChildren
would successfully run.
The androidx.media2.session.MediaLibraryService.MediaLibrarySession
would require the explicit browsable type for the media items returned by the androidx.media2.session.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 androidx.media2.session.MediaLibraryService.MediaLibrarySession
would require the explicit playable value for the media items returned by the androidx.media2.session.MediaLibraryService.MediaLibrarySession.MediaLibrarySessionCallback
.
Duration
The duration is the length of the contents. The androidx.media2.session.MediaController
can only get the duration through the metadata. This tells when would the playback ends, and also tells about the allowed range of androidx.media2.session.MediaController#seekTo(long)
.
If it's not set by developer, androidx.media2.session.MediaSession
would update the duration in the metadata with the SessionPlayer#getDuration()
.
User rating
Prefer to have unrated user rating instead of null
, so androidx.media2.session.MediaController
can know the possible user rating type for calling androidx.media2.session.MediaController#setRating(String, Rating)
.
Summary
Nested classes | |
---|---|
Use to build MediaMetadatax objects. |
Constants | |
---|---|
static Long |
The type of browsable that contains browsable items categorized by album. |
static Long |
The type of browsable that contains browsable items categorized by artist. |
static Long |
The type of browsable that contains browsable items categorized by genre. |
static Long |
The type of browsable that is unknown or contains media items of mixed types. |
static Long |
The type of browsable for non-browsable media item. |
static Long |
The type of browsable that contains browsable items categorized by playlist. |
static Long |
The type of browsable that only contains playable media items. |
static Long |
The type of browsable that contains browsable items categorized by year. |
static String |
The metadata key for a |
static String |
The metadata key for a |
static String |
The metadata key for a |
static String |
The metadata key for a |
static String |
The metadata key for a |
static String |
The metadata key for a |
static String |
The metadata key for a |
static String |
The metadata key for a |
static String |
The metadata key for a |
static String |
The metadata key for a |
static String |
The metadata key for a |
static String |
The metadata key for a |
static String |
The metadata key for a |
static String |
The metadata key for a |
static String |
The metadata key for a |
static String |
The metadata key for a |
static String |
The metadata key for a |
static String |
The metadata key for a |
static String |
The metadata key for a |
static String |
The metadata key for a |
static String |
The metadata key for a |
static String |
A |
static String |
The metadata key for a |
static String |
The metadata key for a |
static String |
The metadata key for a |
static String |
The metadata key for a |
static String |
The metadata key for a |
static String |
The metadata key for a |
static String |
The metadata key for a |
static String |
The metadata key for a |
static String |
The metadata key for a |
static String |
The metadata key for a |
static String |
The metadata key for a |
static Long |
The status value to indicate the media item is downloaded for later offline playback. |
static Long |
The status value to indicate the media item is being downloaded. |
static Long |
The status value to indicate the media item is not downloaded. |
Public methods | |
---|---|
Boolean |
containsKey(@NonNull key: String) Returns true if the given key is contained in the metadata |
Bitmap? |
Return a |
Bundle? |
Get the extra |
Float |
Return the value associated with the given key, or 0. |
Long |
Returns the value associated with the given key, or 0L if no long exists for the given key. |
String? |
Returns the media id, |