MediaMetadata

public class MediaMetadata extends Object
implements Parcelable

Container class for media metadata. Metadata has a media type, an optional list of images, and a collection of metadata fields. Keys for common metadata fields are predefined as constants, but the application is free to define and use additional fields of its own. Information about the different media types and their associated metadata can be found in the Media Playback Messages documentation.

The values of the predefined fields have predefined types. For example, a track number is an int, a creation date is a String containing an ISO-8601 representation of a date and time, and a section duration is an integer in milliseconds. Attempting to store a value of an incorrect type in a field results in a IllegalArgumentException. The complete list of predefined fields is as follows:

Field Value Type Valid Metadata Types
KEY_CREATION_DATE Date MEDIA_TYPE_PHOTO
KEY_RELEASE_DATE Date MEDIA_TYPE_GENERIC, MEDIA_TYPE_MOVIE, MEDIA_TYPE_TV_SHOW, MEDIA_TYPE_MUSIC_TRACK
KEY_BROADCAST_DATE Date MEDIA_TYPE_TV_SHOW
KEY_TITLE String MEDIA_TYPE_GENERIC, MEDIA_TYPE_MOVIE, MEDIA_TYPE_TV_SHOW, MEDIA_TYPE_MUSIC_TRACK, MEDIA_TYPE_PHOTO, MEDIA_TYPE_AUDIOBOOK_CHAPTER
KEY_SUBTITLE String MEDIA_TYPE_GENERIC, MEDIA_TYPE_MOVIE, MEDIA_TYPE_AUDIOBOOK_CHAPTER
KEY_ARTIST String MEDIA_TYPE_GENERIC, MEDIA_TYPE_MUSIC_TRACK, MEDIA_TYPE_PHOTO
KEY_ALBUM_ARTIST String MEDIA_TYPE_MUSIC_TRACK
KEY_ALBUM_TITLE String MEDIA_TYPE_MUSIC_TRACK
KEY_COMPOSER String MEDIA_TYPE_MUSIC_TRACK
KEY_DISC_NUMBER Integer MEDIA_TYPE_MUSIC_TRACK
KEY_TRACK_NUMBER Integer MEDIA_TYPE_MUSIC_TRACK
KEY_SEASON_NUMBER Integer MEDIA_TYPE_TV_SHOW
KEY_EPISODE_NUMBER Integer MEDIA_TYPE_TV_SHOW
KEY_SERIES_TITLE String MEDIA_TYPE_TV_SHOW
KEY_STUDIO String MEDIA_TYPE_MOVIE
KEY_WIDTH Integer MEDIA_TYPE_PHOTO
KEY_HEIGHT Integer MEDIA_TYPE_PHOTO
KEY_LOCATION_NAME String MEDIA_TYPE_PHOTO
KEY_LOCATION_LATITUDE Double MEDIA_TYPE_PHOTO
KEY_LOCATION_LONGITUDE Double MEDIA_TYPE_PHOTO
KEY_BOOK_TITLE String MEDIA_TYPE_AUDIOBOOK_CHAPTER
KEY_CHAPTER_TITLE String MEDIA_TYPE_AUDIOBOOK_CHAPTER
KEY_CHAPTER_NUMBER Integer MEDIA_TYPE_AUDIOBOOK_CHAPTER
KEY_QUEUE_ITEM_ID Integer All types
KEY_SECTION_DURATION Time in milliseconds All types
KEY_SECTION_START_ABSOLUTE_TIME Time in milliseconds All types
KEY_SECTION_START_TIME_IN_CONTAINER Time in milliseconds All types
KEY_SECTION_START_TIME_IN_MEDIA Time in milliseconds All types

Note that the Cast protocol limits which metadata fields can be used for a given media type. When a MediaMetadata object is serialized to JSON for delivery to a Cast receiver, any predefined fields which are not supported for a given media type are not included in the serialized form, but any application-defined fields are always included.

Constant Summary

String KEY_ALBUM_ARTIST String key: Album artist.
String KEY_ALBUM_TITLE String key: Album title.
String KEY_ARTIST String key: Artist.
String KEY_BOOK_TITLE String key: Audiobook title.
String KEY_BROADCAST_DATE String key: Broadcast date.
String KEY_CHAPTER_NUMBER String key: Chapter number.
String KEY_CHAPTER_TITLE String key: Chapter title.
String KEY_COMPOSER String key: Composer.
String KEY_CREATION_DATE String key: Creation date.
String KEY_DISC_NUMBER Integer key: Disc number.
String KEY_EPISODE_NUMBER Integer key: Episode number.
String KEY_HEIGHT Integer key: Height.
String KEY_LOCATION_LATITUDE Double key: Location latitude.
String KEY_LOCATION_LONGITUDE Double key: Location longitude.
String KEY_LOCATION_NAME String key: Location name.
String KEY_QUEUE_ITEM_ID Int key: Queue item ID.
String KEY_RELEASE_DATE String key: Release date.
String KEY_SEASON_NUMBER Integer key: Season number.
String KEY_SECTION_DURATION Time key in milliseconds: section duration.
String KEY_SECTION_START_ABSOLUTE_TIME Time key in milliseconds: section start absolute time.
String KEY_SECTION_START_TIME_IN_CONTAINER Time key in milliseconds: section start time in the container.
String KEY_SECTION_START_TIME_IN_MEDIA Time key in milliseconds: section start time in media item.
String KEY_SERIES_TITLE String key: Series title.
String KEY_STUDIO String key: Studio.
String KEY_SUBTITLE String key: Subtitle.
String KEY_TITLE String key: Title.
String KEY_TRACK_NUMBER Integer key: Track number.
String KEY_WIDTH Integer key: Width.
int MEDIA_TYPE_AUDIOBOOK_CHAPTER A media type representing an audiobook chapter.
int MEDIA_TYPE_GENERIC A media type representing generic media content.
int MEDIA_TYPE_MOVIE A media type representing a movie.
int MEDIA_TYPE_MUSIC_TRACK A media type representing a music track.
int MEDIA_TYPE_PHOTO A media type representing a photo.
int MEDIA_TYPE_TV_SHOW A media type representing an TV show.
int MEDIA_TYPE_USER The smallest media type value that can be assigned for application-defined media types.

Inherited Constant Summary

Public Constructor Summary

MediaMetadata()
Constructs a new, empty, MediaMetadata with a media type of MEDIA_TYPE_GENERIC.
MediaMetadata(int mediaType)
Constructs a new, empty, MediaMetadata with the given media type.

Public Method Summary

void
addImage(WebImage image)
Adds an image to the list of images.
void
clear()
Clears this object.
void
clearImages()
Clears the list of images.
boolean
containsKey(String key)
Tests if the object contains a field with the given key.
boolean
equals(Object other)
Calendar
getDate(String key)
Reads the value of a date field.
String
getDateAsString(String key)
Reads the value of a date field, as a string.
double
getDouble(String key)
Reads the value of a double field.
List<WebImage>
getImages()
Returns the list of images.
int
getInt(String key)
Reads the value of an int field.
int
getMediaType()
Gets the media type.
String
getString(String key)
Reads the value of a String field.
long
getTimeMillis(String key)
Reads the value of a time field, as a long in milliseconds.
boolean
hasImages()
Checks if the metadata includes any images.
int
Set<String>
keySet()
Returns a set of keys for all fields that are present in the object.
void
putDate(String key, Calendar value)
Stores a value in a date field.
void
putDouble(String key, double value)
Stores a value in a double field.
void
putInt(String key, int value)
Stores a value in an int field.
void
putString(String key, String value)
Stores a value in a String field.
void
putTimeMillis(String key, long value)
Stores a value in a time field.
void
writeToParcel(Parcel out, int flags)

Inherited Method Summary

Constants

public static final String KEY_ALBUM_ARTIST

String key: Album artist.

The name of the artist who produced an album. For example, in compilation albums such as DJ mixes, the album artist is not necessarily the same as the artist(s) of the individual songs on the album. This value is suitable for display purposes.

Constant Value: "com.google.android.gms.cast.metadata.ALBUM_ARTIST"

public static final String KEY_ALBUM_TITLE

String key: Album title.

The title of the album that a music track belongs to. This value is suitable for display purposes.

Constant Value: "com.google.android.gms.cast.metadata.ALBUM_TITLE"

public static final String KEY_ARTIST

String key: Artist.

The name of the artist who created the media. For example, this could be the name of a musician, performer, or photographer. This value is suitable for display purposes.

Constant Value: "com.google.android.gms.cast.metadata.ARTIST"

public static final String KEY_BOOK_TITLE

String key: Audiobook title.

The title of the audiobook.

Constant Value: "com.google.android.gms.cast.metadata.BOOK_TITLE"

public static final String KEY_BROADCAST_DATE

String key: Broadcast date.

The value is the date and/or time at which the media was first broadcast, in ISO-8601 format. For example, this could be the date that a TV show episode was first aired.

Constant Value: "com.google.android.gms.cast.metadata.BROADCAST_DATE"

public static final String KEY_CHAPTER_NUMBER

String key: Chapter number.

The chapter number of the audiobook.

Constant Value: "com.google.android.gms.cast.metadata.CHAPTER_NUMBER"

public static final String KEY_CHAPTER_TITLE

String key: Chapter title.

The title of the chapter of the audiobook.

Constant Value: "com.google.android.gms.cast.metadata.CHAPTER_TITLE"

public static final String KEY_COMPOSER

String key: Composer.

The name of the composer of a music track. This value is suitable for display purposes.

Constant Value: "com.google.android.gms.cast.metadata.COMPOSER"

public static final String KEY_CREATION_DATE

String key: Creation date.

The value is the date and/or time at which the media was created, in ISO-8601 format. For example, this could be the date and time at which a photograph was taken or a piece of music was recorded.

Constant Value: "com.google.android.gms.cast.metadata.CREATION_DATE"

public static final String KEY_DISC_NUMBER

Integer key: Disc number.

The disc number (counting from 1) that a music track belongs to in a multi-disc album.

Constant Value: "com.google.android.gms.cast.metadata.DISC_NUMBER"

public static final String KEY_EPISODE_NUMBER

Integer key: Episode number.

The number of an episode in a given season of a TV show. Typically episode numbers are counted starting from 1, however this value may be 0 if it is a "pilot" episode that is not considered to be an official episode of the first season.

Constant Value: "com.google.android.gms.cast.metadata.EPISODE_NUMBER"

public static final String KEY_HEIGHT

Integer key: Height.

The height of a piece of media, in pixels. This would typically be used for providing the dimensions of a photograph.

Constant Value: "com.google.android.gms.cast.metadata.HEIGHT"

public static final String KEY_LOCATION_LATITUDE

Double key: Location latitude.

The latitude component of the geographical location where a piece of media was created. For example, this could be the location of a photograph or the principal filming location of a movie.

Constant Value: "com.google.android.gms.cast.metadata.LOCATION_LATITUDE"

public static final String KEY_LOCATION_LONGITUDE

Double key: Location longitude.

The longitude component of the geographical location where a piece of media was created. For example, this could be the location of a photograph or the principal filming location of a movie.

Constant Value: "com.google.android.gms.cast.metadata.LOCATION_LONGITUDE"

public static final String KEY_LOCATION_NAME

String key: Location name.

The name of a location where a piece of media was created. For example, this could be the location of a photograph or the principal filming location of a movie. This value is suitable for display purposes.

Constant Value: "com.google.android.gms.cast.metadata.LOCATION_NAME"

public static final String KEY_QUEUE_ITEM_ID

Int key: Queue item ID.

The ID of the queue item that includes the section start time.

Constant Value: "com.google.android.gms.cast.metadata.QUEUE_ITEM_ID"

public static final String KEY_RELEASE_DATE

String key: Release date.

The value is the date and/or time at which the media was released, in ISO-8601 format. For example, this could be the date that a movie or music album was released.

Constant Value: "com.google.android.gms.cast.metadata.RELEASE_DATE"

public static final String KEY_SEASON_NUMBER

Integer key: Season number.

The season number that a TV show episode belongs to. Typically season numbers are counted starting from 1, however this value may be 0 if it is a "pilot" episode that predates the official start of a TV series.

Constant Value: "com.google.android.gms.cast.metadata.SEASON_NUMBER"

public static final String KEY_SECTION_DURATION

Time key in milliseconds: section duration.

The section duration in milliseconds.

Constant Value: "com.google.android.gms.cast.metadata.SECTION_DURATION"

public static final String KEY_SECTION_START_ABSOLUTE_TIME

Time key in milliseconds: section start absolute time.

For live content, this field can be used to specify the absolute section start time. The value is in Epoch time in milliseconds.

Constant Value: "com.google.android.gms.cast.metadata.SECTION_START_ABSOLUTE_TIME"

public static final String KEY_SECTION_START_TIME_IN_CONTAINER

Time key in milliseconds: section start time in the container.

Povides section start offset within the full container. For example audiobook chapter offset within the whole book.

Constant Value: "com.google.android.gms.cast.metadata.SECTION_START_TIME_IN_CONTAINER"

public static final String KEY_SECTION_START_TIME_IN_MEDIA

Time key in milliseconds: section start time in media item.

Offset of the section start time from the start of the media item (as specified by KEY_QUEUE_ITEM_ID) in milliseconds.

Constant Value: "com.google.android.gms.cast.metadata.SECTION_START_TIME_IN_MEDIA"

public static final String KEY_SERIES_TITLE

String key: Series title.

The name of a series. For example, this could be the name of a TV show or series of related music albums. This value is suitable for display purposes.

Constant Value: "com.google.android.gms.cast.metadata.SERIES_TITLE"

public static final String KEY_STUDIO

String key: Studio.

The name of a recording studio that produced a piece of media. For example, this could be the name of a movie studio or music label. This value is suitable for display purposes.

Constant Value: "com.google.android.gms.cast.metadata.STUDIO"

public static final String KEY_SUBTITLE

String key: Subtitle.

The subtitle of the media. This value is suitable for display purposes.

Constant Value: "com.google.android.gms.cast.metadata.SUBTITLE"

public static final String KEY_TITLE

String key: Title.

The title of the media. For example, this could be the title of a song, movie, or TV show episode. This value is suitable for display purposes.

Constant Value: "com.google.android.gms.cast.metadata.TITLE"

public static final String KEY_TRACK_NUMBER

Integer key: Track number.

The track number of a music track on an album disc. Typically track numbers are counted starting from 1, however this value may be 0 if it is a "hidden track" at the beginning of an album.

Constant Value: "com.google.android.gms.cast.metadata.TRACK_NUMBER"

public static final String KEY_WIDTH

Integer key: Width.

The width of a piece of media, in pixels. This would typically be used for providing the dimensions of a photograph.

Constant Value: "com.google.android.gms.cast.metadata.WIDTH"

public static final int MEDIA_TYPE_AUDIOBOOK_CHAPTER

A media type representing an audiobook chapter.

Constant Value: 5

public static final int MEDIA_TYPE_GENERIC

A media type representing generic media content.

Constant Value: 0

public static final int MEDIA_TYPE_MOVIE

A media type representing a movie.

Constant Value: 1

public static final int MEDIA_TYPE_MUSIC_TRACK

A media type representing a music track.

Constant Value: 3

public static final int MEDIA_TYPE_PHOTO

A media type representing a photo.

Constant Value: 4

public static final int MEDIA_TYPE_TV_SHOW

A media type representing an TV show.

Constant Value: 2

public static final int MEDIA_TYPE_USER

The smallest media type value that can be assigned for application-defined media types.

Constant Value: 100

Public Constructors

public MediaMetadata ()

Constructs a new, empty, MediaMetadata with a media type of MEDIA_TYPE_GENERIC.

public MediaMetadata (int mediaType)

Constructs a new, empty, MediaMetadata with the given media type.

Parameters
mediaType The media type; one of the MEDIA_TYPE_* constants, or a value greater than or equal to MEDIA_TYPE_USER for custom media types.

Public Methods

public void addImage (WebImage image)

Adds an image to the list of images.

public void clear ()

Clears this object. The media type is left unchanged.

public void clearImages ()

Clears the list of images.

public boolean containsKey (String key)

Tests if the object contains a field with the given key.

public boolean equals (Object other)

public Calendar getDate (String key)

Reads the value of a date field.

Parameters
key The field name.
Returns
  • The date, as a Calendar, or null if this field has not been set.
Throws
IllegalArgumentException If the key is null or empty or the specified field's predefined type is not a date.

public String getDateAsString (String key)

Reads the value of a date field, as a string.

Parameters
key The field name.
Returns
  • The date, as a String containing hte ISO-8601 representation of the date, or null if this field has not been set.
Throws
IllegalArgumentException If the key is null or empty or the specified field's predefined type is not a date.

public double getDouble (String key)

Reads the value of a double field.

Returns
  • The value of the field, or 0 if the field has not been set.
Throws
IllegalArgumentException If the key is null or empty or refers to a predefined field which is not a double field.

public List<WebImage> getImages ()

Returns the list of images. If there are no images, returns an empty list.

public int getInt (String key)

Reads the value of an int field.

Returns
  • The value of the field, or 0 if the field has not been set.
Throws
IllegalArgumentException If the key is null or empty or refers to a predefined field which is not an int field.

public int getMediaType ()

Gets the media type.

public String getString (String key)

Reads the value of a String field.

Returns
  • The value of the field, or null if the field has not been set.
Throws
IllegalArgumentException If the key is null or empty or refers to a predefined field which is not a String field.

public long getTimeMillis (String key)

Reads the value of a time field, as a long in milliseconds.

Parameters
key the field name
Returns
  • the time, as long in milliseconds, or 0L if the field has not been set
Throws
IllegalArgumentException If the key is null or empty or the specified field's predefined type is not time

public boolean hasImages ()

Checks if the metadata includes any images.

public int hashCode ()

public Set<String> keySet ()

Returns a set of keys for all fields that are present in the object.

public void putDate (String key, Calendar value)

Stores a value in a date field.

Parameters
key The key for the field.
value The new value for the field.
Throws
IllegalArgumentException If the key is null or empty or refers to a predefined field which is not a date field.

public void putDouble (String key, double value)

Stores a value in a double field.

Parameters
key The key for the field.
value The new value for the field.
Throws
IllegalArgumentException If the key is null or empty or refers to a predefined field which is not a double field.

public void putInt (String key, int value)

Stores a value in an int field.

Parameters
key The key for the field.
value The new value for the field.
Throws
IllegalArgumentException If the key is null or empty or refers to a predefined field which is not an int field.

public void putString (String key, String value)

Stores a value in a String field.

Parameters
key The key for the field.
value The new value for the field.
Throws
IllegalArgumentException If the key is null or empty or refers to a predefined field which is not a String field.

public void putTimeMillis (String key, long value)

Stores a value in a time field.

Parameters
key the key for the field
value the new value for the field, as long in milliseconds
Throws
IllegalArgumentException If the key is null or empty or refers to a predefined field which is not a time field

public void writeToParcel (Parcel out, int flags)