FileDocCategorySizeDatePackage
MediaMetadata.javaAPI DocAndroid 5.1 API30138Thu Mar 12 22:22:30 GMT 2015android.media

MediaMetadata

public final class MediaMetadata 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. The format is unspecified but RFC 3339 is recommended.
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}.

The artwork should be relatively small and may be scaled down by the system if it is too large. For higher resolution artwork {@link #METADATA_KEY_ART_URI} should be used instead.

public static final String
METADATA_KEY_ART_URI
The artwork for the media as a Uri formatted String. The artwork can be loaded using a combination of {@link ContentResolver#openInputStream} and {@link BitmapFactory#decodeStream}.

For the best results, Uris should use the content:// style and support {@link ContentResolver#EXTRA_SIZE} for retrieving scaled artwork through {@link ContentResolver#openTypedAssetFileDescriptor(Uri, String, Bundle)}.

public static final String
METADATA_KEY_ALBUM_ART
The artwork for the album of the media's original source as a {@link Bitmap}.

The artwork should be relatively small and may be scaled down by the system if it is too large. For higher resolution artwork {@link #METADATA_KEY_ALBUM_ART_URI} should be used instead.

public static final String
METADATA_KEY_ALBUM_ART_URI
The artwork for the album of the media's original source as a Uri formatted String. The artwork can be loaded using a combination of {@link ContentResolver#openInputStream} and {@link BitmapFactory#decodeStream}.

For the best results, Uris should use the content:// style and support {@link ContentResolver#EXTRA_SIZE} for retrieving scaled artwork through {@link ContentResolver#openTypedAssetFileDescriptor(Uri, String, Bundle)}.

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}.

The icon should be relatively small and may be scaled down by the system if it is too large. For higher resolution artwork {@link #METADATA_KEY_DISPLAY_ICON_URI} should be used instead.

public static final String
METADATA_KEY_DISPLAY_ICON_URI
A Uri formatted String for 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. The icon can be loaded using a combination of {@link ContentResolver#openInputStream} and {@link BitmapFactory#decodeStream}.

For the best results, Uris should use the content:// style and support {@link ContentResolver#EXTRA_SIZE} for retrieving scaled artwork through {@link ContentResolver#openTypedAssetFileDescriptor(Uri, String, Bundle)}.

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. It may be used with {@link MediaController.TransportControls#playFromMediaId(String, Bundle)} to initiate playback when provided by a {@link MediaBrowser} connected to the same app.
private static final String[]
PREFERRED_DESCRIPTION_ORDER
private static final String[]
PREFERRED_BITMAP_ORDER
private static final String[]
PREFERRED_URI_ORDER
private static final int
METADATA_TYPE_INVALID
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.util.ArrayMap
METADATA_KEYS_TYPE
private static final android.util.SparseArray
EDITOR_KEY_MAPPING
private final android.os.Bundle
mBundle
private MediaDescription
mDescription
public static final Parcelable.Creator
CREATOR
Constructors Summary
private MediaMetadata(android.os.Bundle bundle)

        mBundle = new Bundle(bundle);
    
private MediaMetadata(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 android.graphics.BitmapgetBitmap(java.lang.String key)
Returns 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 MediaDescriptiongetDescription()
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;
            }
        }

        MediaDescription.Builder bob = new MediaDescription.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 static java.lang.StringgetKeyFromMetadataEditorKey(int editorKey)
Helper for getting the String key used by {@link MediaMetadata} from the integer key that {@link MediaMetadataEditor} uses.

param
editorKey The key used by the editor
return
The key used by this class or null if no mapping exists
hide

        return EDITOR_KEY_MAPPING.get(editorKey, null);
    
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 RatinggetRating(java.lang.String key)
Returns a {@link Rating} 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 Rating} or null

        Rating 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 text value associated with the given key as a String, or null if no mapping of the desired type exists for the given key or a null value is explicitly associated with the key. This is equivalent to calling {@link #getText getText().toString()} if the value is not null.

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

        CharSequence text = getText(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()
Returns 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);