FileDocCategorySizeDatePackage
MediaMetadataCompat.javaAPI DocAndroid 5.1 API27543Thu Mar 12 22:22:56 GMT 2015android.support.v4.media

MediaMetadataCompat

public final class MediaMetadataCompat extends Object implements android.os.Parcelable
Contains metadata about an item, such as the title, artist, etc.

Fields Summary
private static final String
TAG
public static final String
METADATA_KEY_TITLE
The title of the media.
public static final String
METADATA_KEY_ARTIST
The artist of the media.
public static final String
METADATA_KEY_DURATION
The duration of the media in ms. A negative duration indicates that the duration is unknown (or infinite).
public static final String
METADATA_KEY_ALBUM
The album title for the media.
public static final String
METADATA_KEY_AUTHOR
The author of the media.
public static final String
METADATA_KEY_WRITER
The writer of the media.
public static final String
METADATA_KEY_COMPOSER
The composer of the media.
public static final String
METADATA_KEY_COMPILATION
The compilation status of the media.
public static final String
METADATA_KEY_DATE
The date the media was created or published as TODO determine format.
public static final String
METADATA_KEY_YEAR
The year the media was created or published as a long.
public static final String
METADATA_KEY_GENRE
The genre of the media.
public static final String
METADATA_KEY_TRACK_NUMBER
The track number for the media.
public static final String
METADATA_KEY_NUM_TRACKS
The number of tracks in the media's original source.
public static final String
METADATA_KEY_DISC_NUMBER
The disc number for the media's original source.
public static final String
METADATA_KEY_ALBUM_ARTIST
The artist for the album of the media's original source.
public static final String
METADATA_KEY_ART
The artwork for the media as a {@link Bitmap}.
public static final String
METADATA_KEY_ART_URI
The artwork for the media as a Uri style String.
public static final String
METADATA_KEY_ALBUM_ART
The artwork for the album of the media's original source as a {@link Bitmap}.
public static final String
METADATA_KEY_ALBUM_ART_URI
The artwork for the album of the media's original source as a Uri style String.
public static final String
METADATA_KEY_USER_RATING
The user's rating for the media.
public static final String
METADATA_KEY_RATING
The overall rating for the media.
public static final String
METADATA_KEY_DISPLAY_TITLE
A title that is suitable for display to the user. This will generally be the same as {@link #METADATA_KEY_TITLE} but may differ for some formats. When displaying media described by this metadata this should be preferred if present.
public static final String
METADATA_KEY_DISPLAY_SUBTITLE
A 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.
public static final String
METADATA_KEY_DISPLAY_DESCRIPTION
A 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.
public static final String
METADATA_KEY_DISPLAY_ICON
An 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. This must be a {@link Bitmap}.
public static final String
METADATA_KEY_DISPLAY_ICON_URI
An 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. This must be a Uri style String.
public static final String
METADATA_KEY_MEDIA_ID
A String key for identifying 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.
private static final int
METADATA_TYPE_LONG
private static final int
METADATA_TYPE_TEXT
private static final int
METADATA_TYPE_BITMAP
private static final int
METADATA_TYPE_RATING
private static final android.support.v4.util.ArrayMap
METADATA_KEYS_TYPE
private static final String[]
PREFERRED_DESCRIPTION_ORDER
private static final String[]
PREFERRED_BITMAP_ORDER
private static final String[]
PREFERRED_URI_ORDER
private final android.os.Bundle
mBundle
private Object
mMetadataObj
private MediaDescriptionCompat
mDescription
public static final Parcelable.Creator
CREATOR
Constructors Summary
private MediaMetadataCompat(android.os.Bundle bundle)


       
        mBundle = new Bundle(bundle);
    
private MediaMetadataCompat(android.os.Parcel in)

        mBundle = in.readBundle();
    
Methods Summary
public booleancontainsKey(java.lang.String key)
Returns true if the given key is contained in the metadata

param
key a String key
return
true if the key exists in this metadata, false otherwise

        return mBundle.containsKey(key);
    
public intdescribeContents()

        return 0;
    
public static android.support.v4.media.MediaMetadataCompatfromMediaMetadata(java.lang.Object metadataObj)
Creates an instance from a framework {@link android.media.MediaMetadata} object.

This method is only supported on {@link android.os.Build.VERSION_CODES#LOLLIPOP} and later.

param
metadataObj A {@link android.media.MediaMetadata} object, or null if none.
return
An equivalent {@link MediaMetadataCompat} object, or null if none.

        if (metadataObj == null || Build.VERSION.SDK_INT < 21) {
            return null;
        }

        Builder builder = new Builder();
        for (String key : MediaMetadataCompatApi21.keySet(metadataObj)) {
            Integer type = METADATA_KEYS_TYPE.get(key);
            if (type != null) {
                switch (type) {
                    case METADATA_TYPE_BITMAP:
                        builder.putBitmap(key,
                                MediaMetadataCompatApi21.getBitmap(metadataObj, key));
                        break;
                    case METADATA_TYPE_LONG:
                        builder.putLong(key,
                                MediaMetadataCompatApi21.getLong(metadataObj, key));
                        break;
                    case METADATA_TYPE_RATING:
                        builder.putRating(key, RatingCompat.fromRating(
                                MediaMetadataCompatApi21.getRating(metadataObj, key)));
                        break;
                    case METADATA_TYPE_TEXT:
                        builder.putText(key,
                                MediaMetadataCompatApi21.getText(metadataObj, key));
                        break;
                }
            }
        }
        MediaMetadataCompat metadata = builder.build();
        metadata.mMetadataObj = metadataObj;
        return metadata;
    
public android.graphics.BitmapgetBitmap(java.lang.String key)
Return a {@link Bitmap} for the given key or null if no bitmap exists for the given key.

param
key The key the value is stored under
return
A {@link Bitmap} or null

        Bitmap bmp = null;
        try {
            bmp = mBundle.getParcelable(key);
        } catch (Exception e) {
            // ignore, value was not a bitmap
            Log.w(TAG, "Failed to retrieve a key as Bitmap.", e);
        }
        return bmp;
    
public android.os.BundlegetBundle()
Gets the bundle backing the metadata object. This is available to support backwards compatibility. Apps should not modify the bundle directly.

return
The Bundle backing this metadata.

        return mBundle;
    
public MediaDescriptionCompatgetDescription()
Returns a simple description of this metadata for display purposes.

return
A simple description of this metadata.

        if (mDescription != null) {
            return mDescription;
        }

        String mediaId = getString(METADATA_KEY_MEDIA_ID);

        CharSequence[] text = new CharSequence[3];
        Bitmap icon = null;
        Uri iconUri = null;

        // First handle the case where display data is set already
        CharSequence displayText = getText(METADATA_KEY_DISPLAY_TITLE);
        if (!TextUtils.isEmpty(displayText)) {
            // If they have a display title use only display data, otherwise use
            // our best bets
            text[0] = displayText;
            text[1] = getText(METADATA_KEY_DISPLAY_SUBTITLE);
            text[2] = getText(METADATA_KEY_DISPLAY_DESCRIPTION);
        } else {
            // Use whatever fields we can
            int textIndex = 0;
            int keyIndex = 0;
            while (textIndex < text.length && keyIndex < PREFERRED_DESCRIPTION_ORDER.length) {
                CharSequence next = getText(PREFERRED_DESCRIPTION_ORDER[keyIndex++]);
                if (!TextUtils.isEmpty(next)) {
                    // Fill in the next empty bit of text
                    text[textIndex++] = next;
                }
            }
        }

        // Get the best art bitmap we can find
        for (int i = 0; i < PREFERRED_BITMAP_ORDER.length; i++) {
            Bitmap next = getBitmap(PREFERRED_BITMAP_ORDER[i]);
            if (next != null) {
                icon = next;
                break;
            }
        }

        // Get the best Uri we can find
        for (int i = 0; i < PREFERRED_URI_ORDER.length; i++) {
            String next = getString(PREFERRED_URI_ORDER[i]);
            if (!TextUtils.isEmpty(next)) {
                iconUri = Uri.parse(next);
                break;
            }
        }

        MediaDescriptionCompat.Builder bob = new MediaDescriptionCompat.Builder();
        bob.setMediaId(mediaId);
        bob.setTitle(text[0]);
        bob.setSubtitle(text[1]);
        bob.setDescription(text[2]);
        bob.setIconBitmap(icon);
        bob.setIconUri(iconUri);
        mDescription = bob.build();

        return mDescription;
    
public longgetLong(java.lang.String key)
Returns the value associated with the given key, or 0L if no long exists for the given key.

param
key The key the value is stored under
return
a long value

        return mBundle.getLong(key, 0);
    
public java.lang.ObjectgetMediaMetadata()
Gets the underlying framework {@link android.media.MediaMetadata} object.

This method is only supported on {@link android.os.Build.VERSION_CODES#LOLLIPOP} and later.

return
An equivalent {@link android.media.MediaMetadata} object, or null if none.

        if (mMetadataObj != null || Build.VERSION.SDK_INT < 21) {
            return mMetadataObj;
        }

        Object builderObj = MediaMetadataCompatApi21.Builder.newInstance();
        for (String key : keySet()) {
            Integer type = METADATA_KEYS_TYPE.get(key);
            if (type != null) {
                switch (type) {
                    case METADATA_TYPE_BITMAP:
                        MediaMetadataCompatApi21.Builder.putBitmap(builderObj, key,
                                getBitmap(key));
                        break;
                    case METADATA_TYPE_LONG:
                        MediaMetadataCompatApi21.Builder.putLong(builderObj, key,
                                getLong(key));
                        break;
                    case METADATA_TYPE_RATING:
                        MediaMetadataCompatApi21.Builder.putRating(builderObj, key,
                                getRating(key).getRating());
                        break;
                    case METADATA_TYPE_TEXT:
                        MediaMetadataCompatApi21.Builder.putText(builderObj, key,
                                getText(key));
                        break;
                }
            }
        }
        mMetadataObj = MediaMetadataCompatApi21.Builder.build(builderObj);
        return mMetadataObj;
    
public RatingCompatgetRating(java.lang.String key)
Return a {@link RatingCompat} for the given key or null if no rating exists for the given key.

param
key The key the value is stored under
return
A {@link RatingCompat} or null

        RatingCompat rating = null;
        try {
            rating = mBundle.getParcelable(key);
        } catch (Exception e) {
            // ignore, value was not a bitmap
            Log.w(TAG, "Failed to retrieve a key as Rating.", e);
        }
        return rating;
    
public java.lang.StringgetString(java.lang.String key)
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.

param
key The key the value is stored under
return
a String value, or null

        CharSequence text = mBundle.getCharSequence(key);
        if (text != null) {
            return text.toString();
        }
        return null;
    
public java.lang.CharSequencegetText(java.lang.String key)
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.

param
key The key the value is stored under
return
a CharSequence value, or null

        return mBundle.getCharSequence(key);
    
public java.util.SetkeySet()
Returns a Set containing the Strings used as keys in this metadata.

return
a Set of String keys

        return mBundle.keySet();
    
public intsize()
Get the number of fields in this metadata.

return
The number of fields in the metadata.

        return mBundle.size();
    
public voidwriteToParcel(android.os.Parcel dest, int flags)

        dest.writeBundle(mBundle);