Added in API level 21

Builder


class Builder
kotlin.Any
   ↳ android.media.MediaMetadata.Builder

Use to build MediaMetadata objects. The system defined metadata keys must use the appropriate data type.

Summary

Public constructors

Create an empty Builder.

Create a Builder using a MediaMetadata instance to set the initial values.

Public methods
MediaMetadata!

Creates a MediaMetadata instance with the specified fields.

MediaMetadata.Builder!
putBitmap(key: String!, value: Bitmap!)

Put a Bitmap into the metadata.

MediaMetadata.Builder!
putLong(key: String!, value: Long)

Put a long value into the metadata.

MediaMetadata.Builder!
putRating(key: String!, value: Rating!)

Put a Rating into the metadata.

MediaMetadata.Builder!
putString(key: String!, value: String!)

Put a String value into the metadata.

MediaMetadata.Builder!
putText(key: String!, value: CharSequence!)

Put a CharSequence value into the metadata.

MediaMetadata.Builder
setBitmapDimensionLimit(bitmapDimensionLimit: Int)

Sets the maximum width/height (in pixels) for the bitmaps in the metadata.

Public constructors

Builder

Added in API level 21
Builder()

Create an empty Builder. Any field that should be included in the MediaMetadata must be added.

Builder

Added in API level 21
Builder(source: MediaMetadata!)

Create a Builder using a MediaMetadata instance to set the initial values. All fields in the source metadata will be included in the new metadata. Fields can be overwritten by adding the same key.

Parameters
source MediaMetadata!:

Public methods

build

Added in API level 21
fun build(): MediaMetadata!

Creates a MediaMetadata instance with the specified fields.

Return
MediaMetadata! The new MediaMetadata instance

putBitmap

Added in API level 21
fun putBitmap(
    key: String!,
    value: Bitmap!
): MediaMetadata.Builder!

Put a Bitmap into the metadata. Custom keys may be used, but if the METADATA_KEYs defined in this class are used they may only be one of the following:

Large bitmaps may be scaled down by the system with Builder#setBitmapDimensionLimit(int) when MediaSession#setMetadata is called. To pass full resolution images Uris should be used with putString.

Parameters
key String!: The key for referencing this value Value is android.media.MediaMetadata#METADATA_KEY_ART, android.media.MediaMetadata#METADATA_KEY_ALBUM_ART, or android.media.MediaMetadata#METADATA_KEY_DISPLAY_ICON
value Bitmap!: The Bitmap to store
Return
MediaMetadata.Builder! The Builder to allow chaining

putLong

Added in API level 21
fun putLong(
    key: String!,
    value: Long
): MediaMetadata.Builder!

Put a long value into the metadata. Custom keys may be used, but if the METADATA_KEYs defined in this class are used they may only be one of the following:

Parameters
key String!: The key for referencing this value Value is android.media.MediaMetadata#METADATA_KEY_DURATION, android.media.MediaMetadata#METADATA_KEY_YEAR, android.media.MediaMetadata#METADATA_KEY_TRACK_NUMBER, android.media.MediaMetadata#METADATA_KEY_NUM_TRACKS, android.media.MediaMetadata#METADATA_KEY_DISC_NUMBER, or android.media.MediaMetadata#METADATA_KEY_BT_FOLDER_TYPE
value Long: The long value to store
Return
MediaMetadata.Builder! The Builder to allow chaining

putRating

Added in API level 21
fun putRating(
    key: String!,
    value: Rating!
): MediaMetadata.Builder!

Put a Rating into the metadata. Custom keys may be used, but if the METADATA_KEYs defined in this class are used they may only be one of the following:

Parameters
key String!: The key for referencing this value Value is android.media.MediaMetadata#METADATA_KEY_USER_RATING, or android.media.MediaMetadata#METADATA_KEY_RATING
value Rating!: The Rating value to store
Return
MediaMetadata.Builder! The Builder to allow chaining

putString

Added in API level 21
fun putString(
    key: String!,
    value: String!
): MediaMetadata.Builder!

Put a String value into the metadata. Custom keys may be used, but if the METADATA_KEYs defined in this class are used they may only be one of the following:

Uris for artwork should use the content:// style and support ContentResolver#EXTRA_SIZE for retrieving scaled artwork through ContentResolver#openTypedAssetFileDescriptor(Uri,.

Parameters
key String!: The key for referencing this value Value is android.media.MediaMetadata#METADATA_KEY_TITLE, android.media.MediaMetadata#METADATA_KEY_ARTIST, android.media.MediaMetadata#METADATA_KEY_ALBUM, android.media.MediaMetadata#METADATA_KEY_AUTHOR, android.media.MediaMetadata#METADATA_KEY_WRITER, android.media.MediaMetadata#METADATA_KEY_COMPOSER, android.media.MediaMetadata#METADATA_KEY_COMPILATION, android.media.MediaMetadata#METADATA_KEY_DATE, android.media.MediaMetadata#METADATA_KEY_GENRE, android.media.MediaMetadata#METADATA_KEY_ALBUM_ARTIST, android.media.MediaMetadata#METADATA_KEY_ART_URI, android.media.MediaMetadata#METADATA_KEY_ALBUM_ART_URI, android.media.MediaMetadata#METADATA_KEY_DISPLAY_TITLE, android.media.MediaMetadata#METADATA_KEY_DISPLAY_SUBTITLE, android.media.MediaMetadata#METADATA_KEY_DISPLAY_DESCRIPTION, android.media.MediaMetadata#METADATA_KEY_DISPLAY_ICON_URI, android.media.MediaMetadata#METADATA_KEY_MEDIA_ID, or android.media.MediaMetadata#METADATA_KEY_MEDIA_URI
value String!: The String value to store
Return
MediaMetadata.Builder! The Builder to allow chaining

putText

Added in API level 21
fun putText(
    key: String!,
    value: CharSequence!
): MediaMetadata.Builder!

Put a CharSequence value into the metadata. Custom keys may be used, but if the METADATA_KEYs defined in this class are used they may only be one of the following:

Parameters
key String!: The key for referencing this value Value is android.media.MediaMetadata#METADATA_KEY_TITLE, android.media.MediaMetadata#METADATA_KEY_ARTIST, android.media.MediaMetadata#METADATA_KEY_ALBUM, android.media.MediaMetadata#METADATA_KEY_AUTHOR, android.media.MediaMetadata#METADATA_KEY_WRITER, android.media.MediaMetadata#METADATA_KEY_COMPOSER, android.media.MediaMetadata#METADATA_KEY_COMPILATION, android.media.MediaMetadata#METADATA_KEY_DATE, android.media.MediaMetadata#METADATA_KEY_GENRE, android.media.MediaMetadata#METADATA_KEY_ALBUM_ARTIST, android.media.MediaMetadata#METADATA_KEY_ART_URI, android.media.MediaMetadata#METADATA_KEY_ALBUM_ART_URI, android.media.MediaMetadata#METADATA_KEY_DISPLAY_TITLE, android.media.MediaMetadata#METADATA_KEY_DISPLAY_SUBTITLE, android.media.MediaMetadata#METADATA_KEY_DISPLAY_DESCRIPTION, android.media.MediaMetadata#METADATA_KEY_DISPLAY_ICON_URI, android.media.MediaMetadata#METADATA_KEY_MEDIA_ID, or android.media.MediaMetadata#METADATA_KEY_MEDIA_URI
value CharSequence!: The CharSequence value to store
Return
MediaMetadata.Builder! The Builder to allow chaining

setBitmapDimensionLimit

Added in API level 31
fun setBitmapDimensionLimit(bitmapDimensionLimit: Int): MediaMetadata.Builder

Sets the maximum width/height (in pixels) for the bitmaps in the metadata. Bitmaps will be replaced with scaled down copies if their width (or height) is larger than bitmapDimensionLimit.

In order to unset the limit, pass Integer#MAX_VALUE as bitmapDimensionLimit.

Parameters
bitmapDimensionLimit Int: The maximum width/height (in pixels) for bitmaps contained in the metadata. Non-positive values are ignored. Pass Integer#MAX_VALUE to unset the limit. Value is 1 or greater
Return
MediaMetadata.Builder This value cannot be null.