Save the date! Android Dev Summit is coming to Sunnyvale, CA on Oct 23-24, 2019.

MediaMetadata2

class MediaMetadata2 : VersionedParcelable
kotlin.Any
   ↳ androidx.media2.MediaMetadata2

Contains metadata about an item, such as the title, artist, etc.

Summary

Nested classes

Use to build MediaMetadata2x objects.

Constants
static String

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

static String

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

static String

The metadata key for a Long typed value to retrieve the information about the duration of the media in ms.

static String

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

static String

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

static String

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

static String

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

static String

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

static String

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

static String

The metadata key for a Long typed value to retrieve the information about the year the media was created or published.

static String

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

static String

The metadata key for a Long typed value to retrieve the information about the track number for the media.

static String

The metadata key for a Long typed value to retrieve the information about the number of tracks in the media's original source.

static String

The metadata key for a Long typed value to retrieve the information about the disc number for the media's original source.

static String

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.

static String

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

static String

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

static String

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

static String

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.

static String

The metadata key for a Rating2 typed value to retrieve the information about the user's rating for the media.

static String

The metadata key for a Rating2 typed value to retrieve the information about the overall rating for the media.

static String

The metadata key for a CharSequence or String typed value to retrieve the information about the title that is suitable for display to the user.

static String

The metadata key for a CharSequence or String typed value to retrieve the information about the subtitle that is suitable for display to the user.

static String

The metadata key for a CharSequence or String typed value to retrieve the information about the description that is suitable for display to the user.

static String

The metadata key for a Bitmap typed value to retrieve the information about the icon or thumbnail that is suitable for display to the user.

static String

The metadata key for a CharSequence or String typed value to retrieve the information about the Uri of icon or thumbnail that is suitable for display to the user.

static String

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

static String

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

static String

The metadata key for a Long typed value to retrieve the information about the bluetooth folder type of the media specified in the section 6.

static Long

The type of folder that is unknown or contains media elements of mixed types as specified in the section 6.

static Long

The type of folder that contains media elements only as specified in the section 6.

static Long

The type of folder that contains folders categorized by album as specified in the section 6.

static Long

The type of folder that contains folders categorized by artist as specified in the section 6.

static Long

The type of folder that contains folders categorized by genre as specified in the section 6.

static Long

The type of folder that contains folders categorized by playlist as specified in the section 6.

static Long

The type of folder that contains folders categorized by year as specified in the section 6.

static String

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

static String

The metadata key for a Long typed value to retrieve the information about the download status of the media which will be used for later offline playback.

static Long

The status value to indicate the media item is not downloaded.

static Long

The status value to indicate the media item is being downloaded.

static Long

The status value to indicate the media item is downloaded for later offline playback.

static String

A Bundle extra.

Public methods
Rating2?
getRating(@NonNull key: String)

Return a Rating2 for the given key or null if no rating exists for the given key.

Bundle?

Get the extra Bundle from the metadata object.

Bundle

Gets the bundle backing the metadata object.

Bitmap?
getBitmap(@NonNull key: String)

Return a Bitmap for the given key or null if no bitmap exists for the given key.

CharSequence?
getText(@NonNull key: String)

Returns the value associated with the given key, or null if no mapping of the desired type exists for the given key or a null value is explicitly associated with the key.

Long
getLong(@NonNull key: String)

Returns the value associated with the given key, or 0L if no long exists for the given key.

Float
getFloat(@NonNull key: String)

Return the value associated with the given key, or 0.

Int

Get the number of fields in this metadata.

MutableSet<String!>

Returns a Set containing the Strings used as keys in this metadata.

Boolean
containsKey(@NonNull key: String)

Returns true if the given key is contained in the metadata

String?
getString(@NonNull key: String)

Returns the value associated with the given key, or null if no mapping of the desired type exists for the given key or a null value is explicitly associated with the key.

String?

Returns the media id, or null if the id doesn't exist.

static MediaMetadata2
fromBundle(@Nullable bundle: Bundle?)

Creates the MediaMetadata2 from the bundle that previously returned by toBundle().

Constants

METADATA_KEY_TITLE

static val METADATA_KEY_TITLE: String

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

Value: "android.media.metadata.TITLE"

METADATA_KEY_ARTIST

static val METADATA_KEY_ARTIST: String

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

Value: "android.media.metadata.ARTIST"

METADATA_KEY_DURATION

static val METADATA_KEY_DURATION: String

The metadata key for a Long typed value to retrieve the information about the duration of the media in ms. A negative duration indicates that the duration is unknown (or infinite).

Value: "android.media.metadata.DURATION"

METADATA_KEY_ALBUM

static val METADATA_KEY_ALBUM: String

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

Value: "android.media.metadata.ALBUM"

METADATA_KEY_AUTHOR

static val METADATA_KEY_AUTHOR: String

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

Value: "android.media.metadata.AUTHOR"

METADATA_KEY_WRITER

static val METADATA_KEY_WRITER: String

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

Value: "android.media.metadata.WRITER"

METADATA_KEY_COMPOSER

static val METADATA_KEY_COMPOSER: String

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

Value: "android.media.metadata.COMPOSER"

METADATA_KEY_COMPILATION

static val METADATA_KEY_COMPILATION: String

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

Value: "android.media.metadata.COMPILATION"

METADATA_KEY_DATE

static val METADATA_KEY_DATE: String

The metadata key for a CharSequence or String typed value to retrieve the information about the date the media was created or published. The format is unspecified but RFC 3339 is recommended.

Value: "android.media.metadata.DATE"

METADATA_KEY_YEAR

static val METADATA_KEY_YEAR: String

The metadata key for a Long typed value to retrieve the information about the year the media was created or published.

Value: "android.media.metadata.YEAR"

METADATA_KEY_GENRE

static val METADATA_KEY_GENRE: String

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

Value: "android.media.metadata.GENRE"

METADATA_KEY_TRACK_NUMBER

static val METADATA_KEY_TRACK_NUMBER: String

The metadata key for a Long typed value to retrieve the information about the track number for the media.

Value: "android.media.metadata.TRACK_NUMBER"

METADATA_KEY_NUM_TRACKS

static val METADATA_KEY_NUM_TRACKS: String

The metadata key for a Long typed value to retrieve the information about the number of tracks in the media's original source.

Value: "android.media.metadata.NUM_TRACKS"

METADATA_KEY_DISC_NUMBER

static val METADATA_KEY_DISC_NUMBER: String

The metadata key for a Long typed value to retrieve the information about the disc number for the media's original source.

Value: "android.media.metadata.DISC_NUMBER"

METADATA_KEY_ALBUM_ARTIST

static val METADATA_KEY_ALBUM_ARTIST: String

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.

Value: "android.media.metadata.ALBUM_ARTIST"

METADATA_KEY_ART

static val METADATA_KEY_ART: String

The metadata key for a Bitmap typed value to retrieve the information about the artwork for the media. The artwork should be relatively small and may be scaled down if it is too large. For higher resolution artwork, METADATA_KEY_ART_URI should be used instead.

Value: "android.media.metadata.ART"

METADATA_KEY_ART_URI

static val METADATA_KEY_ART_URI: String

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

Value: "android.media.metadata.ART_URI"

METADATA_KEY_ALBUM_ART

static val METADATA_KEY_ALBUM_ART: String

The metadata key for a Bitmap typed value to retrieve the information about the artwork for the album of the media's original source. The artwork should be relatively small and may be scaled down if it is too large. For higher resolution artwork, METADATA_KEY_ALBUM_ART_URI should be used instead.

Value: "android.media.metadata.ALBUM_ART"

METADATA_KEY_ALBUM_ART_URI

static val METADATA_KEY_ALBUM_ART_URI: String

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.

Value: "android.media.metadata.ALBUM_ART_URI"

METADATA_KEY_USER_RATING

static val METADATA_KEY_USER_RATING: String

The metadata key for a Rating2 typed value to retrieve the information about the user's rating for the media.

Value: "android.media.metadata.USER_RATING"

METADATA_KEY_RATING

static val METADATA_KEY_RATING: String

The metadata key for a Rating2 typed value to retrieve the information about the overall rating for the media.

Value: "android.media.metadata.RATING"

METADATA_KEY_DISPLAY_TITLE

static val METADATA_KEY_DISPLAY_TITLE: String

The metadata key for a CharSequence or String typed value to retrieve the information about the title that is suitable for display to the user. It will generally be the same as METADATA_KEY_TITLE but may differ for some formats. When displaying media described by this metadata, this should be preferred if present.

Value: "android.media.metadata.DISPLAY_TITLE"

METADATA_KEY_DISPLAY_SUBTITLE

static val METADATA_KEY_DISPLAY_SUBTITLE: String

The metadata key for a CharSequence or String typed value to retrieve the information about the subtitle that is suitable for display to the user. When displaying a second line for media described by this metadata, this should be preferred to other fields if present.

Value: "android.media.metadata.DISPLAY_SUBTITLE"

METADATA_KEY_DISPLAY_DESCRIPTION

static val METADATA_KEY_DISPLAY_DESCRIPTION: String

The metadata key for a CharSequence or String typed value to retrieve the information about the description that is suitable for display to the user. When displaying more information for media described by this metadata, this should be preferred to other fields if present.

Value: "android.media.metadata.DISPLAY_DESCRIPTION"

METADATA_KEY_DISPLAY_ICON

static val METADATA_KEY_DISPLAY_ICON: String

The metadata key for a Bitmap typed value to retrieve the information about the icon or thumbnail that is suitable for display to the user. When displaying an icon for media described by this metadata, this should be preferred to other fields if present.

The icon should be relatively small and may be scaled down if it is too large. For higher resolution artwork, METADATA_KEY_DISPLAY_ICON_URI should be used instead.

Value: "android.media.metadata.DISPLAY_ICON"

METADATA_KEY_DISPLAY_ICON_URI

static val METADATA_KEY_DISPLAY_ICON_URI: String

The metadata key for a CharSequence or String typed value to retrieve the information about the Uri of icon or thumbnail that is suitable for display to the user. When displaying more information for media described by this metadata, the display description should be preferred to other fields when present.

Value: "android.media.metadata.DISPLAY_ICON_URI"

METADATA_KEY_MEDIA_ID

static val METADATA_KEY_MEDIA_ID: String

The metadata key for a CharSequence or String typed value to retrieve the information about the media ID of the content. This value is specific to the service providing the content. If used, this should be a persistent unique key for the underlying content. It may be used with MediaController2#playFromMediaId(String, Bundle) to initiate playback.

Value: "android.media.metadata.MEDIA_ID"

METADATA_KEY_MEDIA_URI

static val METADATA_KEY_MEDIA_URI: String

The metadata key for a CharSequence or String typed value to retrieve the information about the Uri of the content. This value is specific to the service providing the content. It may be used with MediaController2#playFromUri(Uri, Bundle) to initiate playback.

Value: "android.media.metadata.MEDIA_URI"

METADATA_KEY_BT_FOLDER_TYPE

static val METADATA_KEY_BT_FOLDER_TYPE: String

The metadata key for a Long typed value to retrieve the information about the bluetooth folder type of the media specified in the section 6.10.2.2 of the Bluetooth AVRCP 1.5. It should be one of the following:

Value: "android.media.metadata.BT_FOLDER_TYPE"

BT_FOLDER_TYPE_MIXED

static val BT_FOLDER_TYPE_MIXED: Long

The type of folder that is unknown or contains media elements of mixed types as specified in the section 6.10.2.2 of the Bluetooth AVRCP 1.5.

Value: 0

BT_FOLDER_TYPE_TITLES

static val BT_FOLDER_TYPE_TITLES: Long

The type of folder that contains media elements only as specified in the section 6.10.2.2 of the Bluetooth AVRCP 1.5.

Value: 1

BT_FOLDER_TYPE_ALBUMS

static val BT_FOLDER_TYPE_ALBUMS: Long

The type of folder that contains folders categorized by album as specified in the section 6.10.2.2 of the Bluetooth AVRCP 1.5.

Value: 2

BT_FOLDER_TYPE_ARTISTS

static val BT_FOLDER_TYPE_ARTISTS: Long

The type of folder that contains folders categorized by artist as specified in the section 6.10.2.2 of the Bluetooth AVRCP 1.5.

Value: 3

BT_FOLDER_TYPE_GENRES

static val BT_FOLDER_TYPE_GENRES: Long

The type of folder that contains folders categorized by genre as specified in the section 6.10.2.2 of the Bluetooth AVRCP 1.5.

Value: 4

BT_FOLDER_TYPE_PLAYLISTS

static val BT_FOLDER_TYPE_PLAYLISTS: Long

The type of folder that contains folders categorized by playlist as specified in the section 6.10.2.2 of the Bluetooth AVRCP 1.5.

Value: 5

BT_FOLDER_TYPE_YEARS

static val BT_FOLDER_TYPE_YEARS: Long

The type of folder that contains folders categorized by year as specified in the section 6.10.2.2 of the Bluetooth AVRCP 1.5.

Value: 6

METADATA_KEY_ADVERTISEMENT

static val METADATA_KEY_ADVERTISEMENT: String

The metadata key for a Long typed value to retrieve the information about whether the media is an advertisement. A value of 0 indicates it is not an advertisement. A value of 1 or non-zero indicates it is an advertisement. If not specified, this value is set to 0 by default.

Value: "android.media.metadata.ADVERTISEMENT"

METADATA_KEY_DOWNLOAD_STATUS

static val METADATA_KEY_DOWNLOAD_STATUS: String

The metadata key for a Long typed value to retrieve the information about the download status of the media which will be used for later offline playback. It should be one of the following:

Value: "android.media.metadata.DOWNLOAD_STATUS"

STATUS_NOT_DOWNLOADED

static val STATUS_NOT_DOWNLOADED: Long

The status value to indicate the media item is not downloaded.

Value: 0

STATUS_DOWNLOADING

static val STATUS_DOWNLOADING: Long

The status value to indicate the media item is being downloaded.

Value: 1

STATUS_DOWNLOADED

static val STATUS_DOWNLOADED: Long

The status value to indicate the media item is downloaded for later offline playback.

Value: 2

METADATA_KEY_EXTRAS

static val METADATA_KEY_EXTRAS: String

A Bundle extra.

Value: "android.media.metadata.EXTRAS"

Public methods

getRating

@Nullable fun getRating(@NonNull key: String): Rating2?

Return a Rating2 for the given key or null if no rating exists for the given key.

For the METADATA_KEY_USER_RATING, A null return value means that user rating cannot be set by MediaController2.

Parameters
key String: The key the value is stored under
Return
Rating2?: A Rating2 or null

getExtras

@Nullable fun getExtras(): Bundle?

Get the extra Bundle from the metadata object.

Return
Bundle?: A Bundle or null

toBundle

@NonNull fun toBundle(): Bundle

Gets the bundle backing the metadata object. This is available to support backwards compatibility. Apps should not modify the bundle directly.

Return
Bundle: The Bundle backing this metadata.

getBitmap

@Nullable fun getBitmap(@NonNull key: String): Bitmap?

Return a Bitmap for the given key or null if no bitmap exists for the given key.

Parameters
key String: The key the value is stored under
Return
Bitmap?: A Bitmap or null

getText

@Nullable fun getText(@NonNull key: String): CharSequence?

Returns the value associated with the given key, or null if no mapping of the desired type exists for the given key or a null value is explicitly associated with the key.

Parameters
key String: The key the value is stored under
Return
CharSequence?: a CharSequence value, or null

getLong

fun getLong(@NonNull key: String): Long

Returns the value associated with the given key, or 0L if no long exists for the given key.

Parameters
key String: The key the value is stored under
Return
Long: a long value

getFloat

fun getFloat(@NonNull key: String): Float

Return the value associated with the given key, or 0.0f if no long exists for the given key.

Parameters
key String: The key the value is stored under
Return
Float: a float value

size

fun size(): Int

Get the number of fields in this metadata.

Return
Int: The number of fields in the metadata.

keySet

@NonNull fun keySet(): MutableSet<String!>

Returns a Set containing the Strings used as keys in this metadata.

Return
MutableSet<String!>: a Set of String keys

containsKey

fun containsKey(@NonNull key: String): Boolean

Returns true if the given key is contained in the metadata

Parameters
key String: a String key
Return
Boolean: true if the key exists in this metadata, false otherwise

getString

@Nullable fun getString(@NonNull key: String): String?

Returns the value associated with the given key, or null if no mapping of the desired type exists for the given key or a null value is explicitly associated with the key.

Parameters
key String: The key the value is stored under
Return
String?: a String value, or null

getMediaId

@Nullable fun getMediaId(): String?

Returns the media id, or null if the id doesn't exist.

This is equivalent to the getString(String) with the METADATA_KEY_MEDIA_ID.

Return
String?: media id. Can be null

fromBundle

@NonNull static fun fromBundle(@Nullable bundle: Bundle?): MediaMetadata2

Creates the MediaMetadata2 from the bundle that previously returned by toBundle().

Parameters
bundle Bundle?: bundle for the metadata
Return
MediaMetadata2: a new MediaMetadata2x