lightbulb_outline Please take our October 2018 developer survey. Start survey

MediaMetadata.Builder

public static final class MediaMetadata.Builder
extends Object

java.lang.Object
   ↳ android.media.MediaMetadata.Builder


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

Summary

Public constructors

MediaMetadata.Builder()

Create an empty Builder.

MediaMetadata.Builder(MediaMetadata source)

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

Public methods

MediaMetadata build()

Creates a MediaMetadata instance with the specified fields.

MediaMetadata.Builder putBitmap(String key, Bitmap value)

Put a Bitmap into the metadata.

MediaMetadata.Builder putLong(String key, long value)

Put a long value into the metadata.

MediaMetadata.Builder putRating(String key, Rating value)

Put a Rating into the metadata.

MediaMetadata.Builder putString(String key, String value)

Put a String value into the metadata.

MediaMetadata.Builder putText(String key, CharSequence value)

Put a CharSequence value into the metadata.

Inherited methods

Public constructors

MediaMetadata.Builder

added in API level 21
public MediaMetadata.Builder ()

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

MediaMetadata.Builder

added in API level 21
public MediaMetadata.Builder (MediaMetadata source)

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.

Public methods

build

added in API level 21
public MediaMetadata build ()

Creates a MediaMetadata instance with the specified fields.

Returns
MediaMetadata The new MediaMetadata instance

putBitmap

added in API level 21
public MediaMetadata.Builder putBitmap (String key, 
                Bitmap value)

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 when MediaSession.setMetadata(MediaMetadata) is called. To pass full resolution images Uris should be used with putString(String, String).

Parameters
key String: The key for referencing this value

Value is METADATA_KEY_ART, METADATA_KEY_ALBUM_ART or METADATA_KEY_DISPLAY_ICON.

value Bitmap: The Bitmap to store

Returns
MediaMetadata.Builder The Builder to allow chaining

putLong

added in API level 21
public MediaMetadata.Builder putLong (String key, 
                long value)

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 METADATA_KEY_DURATION, METADATA_KEY_YEAR, METADATA_KEY_TRACK_NUMBER, METADATA_KEY_NUM_TRACKS, METADATA_KEY_DISC_NUMBER or METADATA_KEY_BT_FOLDER_TYPE.

value long: The long value to store

Returns
MediaMetadata.Builder The Builder to allow chaining

putRating

added in API level 21
public MediaMetadata.Builder putRating (String key, 
                Rating value)

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 METADATA_KEY_USER_RATING or METADATA_KEY_RATING.

value Rating: The Rating value to store

Returns
MediaMetadata.Builder The Builder to allow chaining

putString

added in API level 21
public MediaMetadata.Builder putString (String key, 
                String value)

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, String, Bundle).

Parameters
key String: The key for referencing this value

Value is METADATA_KEY_TITLE, METADATA_KEY_ARTIST, METADATA_KEY_ALBUM, METADATA_KEY_AUTHOR, METADATA_KEY_WRITER, METADATA_KEY_COMPOSER, METADATA_KEY_COMPILATION, METADATA_KEY_DATE, METADATA_KEY_GENRE, METADATA_KEY_ALBUM_ARTIST, METADATA_KEY_ART_URI, METADATA_KEY_ALBUM_ART_URI, METADATA_KEY_DISPLAY_TITLE, METADATA_KEY_DISPLAY_SUBTITLE, METADATA_KEY_DISPLAY_DESCRIPTION, METADATA_KEY_DISPLAY_ICON_URI, METADATA_KEY_MEDIA_ID or METADATA_KEY_MEDIA_URI.

value String: The String value to store

Returns
MediaMetadata.Builder The Builder to allow chaining

putText

added in API level 21
public MediaMetadata.Builder putText (String key, 
                CharSequence value)

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 METADATA_KEY_TITLE, METADATA_KEY_ARTIST, METADATA_KEY_ALBUM, METADATA_KEY_AUTHOR, METADATA_KEY_WRITER, METADATA_KEY_COMPOSER, METADATA_KEY_COMPILATION, METADATA_KEY_DATE, METADATA_KEY_GENRE, METADATA_KEY_ALBUM_ARTIST, METADATA_KEY_ART_URI, METADATA_KEY_ALBUM_ART_URI, METADATA_KEY_DISPLAY_TITLE, METADATA_KEY_DISPLAY_SUBTITLE, METADATA_KEY_DISPLAY_DESCRIPTION, METADATA_KEY_DISPLAY_ICON_URI, METADATA_KEY_MEDIA_ID or METADATA_KEY_MEDIA_URI.

value CharSequence: The CharSequence value to store

Returns
MediaMetadata.Builder The Builder to allow chaining