MPMediaItem Class Reference
| Inherits from | |
| Conforms to | |
| Framework | /System/Library/Frameworks/MediaPlayer.framework |
| Availability | Available in iOS 3.0 and later. |
| Companion guide | |
| Declared in | MPMediaItem.h MPMediaQuery.h |
Overview
A media item represents a single piece of media (such as one song or one video podcast) in the iPod library. A media item has an overall unique identifier, accessed using the MPMediaItemPropertyPersistentID property key, as well as specific identifiers for its metadata. These identifiers persists across application launches.
A media item can have a wide range of metadata associated with it. You access this metadata using the valueForProperty: method along with the property keys described in this document. You can also access metadata in a batch fashion using the enumerateValuesForProperties:usingBlock: method. In some cases, this is more efficient. Both of these methods are defined in MPMediaEntity, the abstract superclass of MPMediaItemCollection, and described in MPMediaEntity Class Reference.
You use attributes of media items to build media queries for searching the iPod library. These attributes are described in “Media Item Type Flags,” “General Media Item Property Keys,” and “Podcast Item Property Keys.” In addition, the MPMediaEntityPropertyPersistentID property is described in Media Entity Property Keys. Media queries are described in MPMediaQuery Class Reference.
Starting in iOS 5.0, a media item can represent a video from the iPod library, whereas previously only audio was supported. See “Media Item Type Flags.”
Class Methods
persistentIDPropertyForGroupingType:
Obtains the persistent identifier key for a specified grouping type.
Parameters
- groupingType
The grouping type that you want the persistent identifier key for.
Discussion
Use this convenience method to obtain the key for a specific persistent identifier based on a grouping type. You can use that key, in turn, to obtain the value of a specific persistent ID of a media item, such as album title or artist name. Using this method simplifies such tasks as drilling down from an artist, to albums by that artist, to a specific album.
For example, the following statement returns the persistent identifier key for the album grouping type:
NSString *albumIDKey = [MPMediaItem persistentIDPropertyForGroupingType: MPMediaGroupingAlbum]; |
You could then obtain the specific persistent ID that you want by using the valueForProperty:method. Grouping keys are described in Media Item Collection Grouping Keys.
Availability
- Available in iOS 4.2 and later.
Declared In
MPMediaQuery.htitlePropertyForGroupingType:
Obtains the title key for a specified grouping type.
Parameters
- groupingType
The grouping type that you want the title key for.
Discussion
Use this convenience method to obtain the key for the title that corresponds to a specified grouping type. For example, the following statement obtains the title key for the album grouping type:
NSString *titleIDKey = [MPMediaItem titlePropertyForGroupingType: MPMediaGroupingAlbum]; |
You could then obtain the specific title that you want by using the valueForProperty: method. Grouping keys are described in Media Item Collection Grouping Keys.
Availability
- Available in iOS 4.2 and later.
Declared In
MPMediaQuery.hConstants
Media Item Type Flags
Media item types, used as possible values for the MPMediaItemPropertyMediaType property. A media item can have more than one media item type.
enum {
// audio media types
MPMediaTypeMusic = 1 << 0,
MPMediaTypePodcast = 1 << 1,
MPMediaTypeAudioBook = 1 << 2,
MPMediaTypeAudioITunesU = 1 << 3, // available in iOS 5.0
MPMediaTypeAnyAudio = 0x00ff,
// video media types
MPMediaTypeMovie = 1 << 8,
MPMediaTypeTVShow = 1 << 9,
MPMediaTypeVideoPodcast = 1 << 10,
MPMediaTypeMusicVideo = 1 << 11,
MPMediaTypeVideoITunesU = 1 << 12,
MPMediaTypeAnyVideo = 0xff00,
// generic media type
MPMediaTypeAny = ~0
};
typedef NSInteger MPMediaType;
Constants
MPMediaTypeMusicIf set, the media item contains music.
Available in iOS 3.0 and later.
Declared in
MPMediaItem.h.MPMediaTypePodcastIf set, the media item contains a podcast.
Available in iOS 3.0 and later.
Declared in
MPMediaItem.h.MPMediaTypeAudioBookIf set, the media item contains an audio book.
Available in iOS 3.0 and later.
Declared in
MPMediaItem.h.MPMediaTypeAnyAudioIf set, the media item contains an unspecified type of audio content.
Available in iOS 3.0 and later.
Declared in
MPMediaItem.h.MPMediaTypeMovieIf set, the media item contains a movie.
Available in iOS 5.0 and later.
Declared in
MPMediaItem.h.MPMediaTypeTVShowIf set, the media item contains a TV show.
Available in iOS 5.0 and later.
Declared in
MPMediaItem.h.MPMediaTypeVideoPodcastIf set, the media item contains a video podcast.
Available in iOS 5.0 and later.
Declared in
MPMediaItem.h.MPMediaTypeMusicVideoIf set, the media item contains a music video.
Available in iOS 5.0 and later.
Declared in
MPMediaItem.h.MPMediaTypeVideoITunesUIf set, the media item contains an iTunes U video.
Available in iOS 5.0 and later.
Declared in
MPMediaItem.h.MPMediaTypeAnyVideoIf set, the media item contains an unspecified type of video content.
Available in iOS 5.0 and later.
Declared in
MPMediaItem.h.MPMediaTypeAnyIf set, the media item contains an unspecified type of audio.
Available in iOS 3.0 and later.
Declared in
MPMediaItem.h.
General Media Item Property Keys
You obtain metadata for a media item by calling the valueForProperty method with these property keys. Some properties can also be used to build media property predicates, as described in MPMediaPropertyPredicate Class Reference. These properties are marked here as filterable.
NSString *const MPMediaItemPropertyPersistentID; // filterable NSString *const MPMediaItemPropertyAlbumPersistentID; // filterable NSString *const MPMediaItemPropertyArtistPersistentID; // filterable NSString *const MPMediaItemPropertyAlbumArtistPersistentID; // filterable NSString *const MPMediaItemPropertyGenrePersistentID; // filterable NSString *const MPMediaItemPropertyComposerPersistentID; // filterable NSString *const MPMediaItemPropertyPodcastPersistentID; // filterable NSString *const MPMediaItemPropertyMediaType; // filterable NSString *const MPMediaItemPropertyTitle; // filterable NSString *const MPMediaItemPropertyAlbumTitle; // filterable NSString *const MPMediaItemPropertyArtist; // filterable NSString *const MPMediaItemPropertyAlbumArtist; // filterable NSString *const MPMediaItemPropertyGenre; // filterable NSString *const MPMediaItemPropertyComposer; // filterable NSString *const MPMediaItemPropertyPlaybackDuration; NSString *const MPMediaItemPropertyAlbumTrackNumber; NSString *const MPMediaItemPropertyAlbumTrackCount; NSString *const MPMediaItemPropertyDiscNumber; NSString *const MPMediaItemPropertyDiscCount; NSString *const MPMediaItemPropertyArtwork; NSString *const MPMediaItemPropertyLyrics; NSString *const MPMediaItemPropertyIsCompilation; // filterable NSString *const MPMediaItemPropertyReleaseDate; NSString *const MPMediaItemPropertyBeatsPerMinute; NSString *const MPMediaItemPropertyComments; NSString *const MPMediaItemPropertyAssetURL; NSString *const MPMediaItemPropertyIsCloudItem; // filterable
Constants
MPMediaItemPropertyPersistentIDThe persistent identifier for the media item. Value is an
NSNumberobject containing auint64_t(unsigned long long).The value of the
MPMediaItemPropertyPersistentIDidentifier persists across application launches and across syncs that do not change the sync status of the media item. The value is not guaranteed to persist across a sync/unsync/sync cycle.Can be used to build a media property predicate as described in MPMediaPropertyPredicate Class Reference.
Available in iOS 3.0 and later.
Declared in
MPMediaItem.h.MPMediaItemPropertyAlbumPersistentIDThe persistent identifier for an album. Value is an
NSNumberobject containing auint64_t(unsigned long long).The value of the
MPMediaItemPropertyAlbumPersistentIDidentifier persists across application launches and across syncs that do not change the sync status of the media item. The value is not guaranteed to persist across a sync/unsync/sync cycle.Can be used to build a media property predicate as described in MPMediaPropertyPredicate Class Reference.
Available in iOS 4.2 and later.
Declared in
MPMediaItem.h.MPMediaItemPropertyArtistPersistentIDThe persistent identifier for an artist. Value is an
NSNumberobject containing auint64_t(unsigned long long).The value of the
MPMediaItemPropertyArtistPersistentIDidentifier persists across application launches and across syncs that do not change the sync status of the media item. The value is not guaranteed to persist across a sync/unsync/sync cycle.Can be used to build a media property predicate as described in MPMediaPropertyPredicate Class Reference.
Available in iOS 4.2 and later.
Declared in
MPMediaItem.h.MPMediaItemPropertyAlbumArtistPersistentIDThe persistent identifier for an album artist. Value is an
NSNumberobject containing auint64_t(unsigned long long).The value of the
MPMediaItemPropertyAlbumArtistPersistentIDidentifier persists across application launches and across syncs that do not change the sync status of the media item. The value is not guaranteed to persist across a sync/unsync/sync cycle.Can be used to build a media property predicate as described in MPMediaPropertyPredicate Class Reference.
Available in iOS 4.2 and later.
Declared in
MPMediaItem.h.MPMediaItemPropertyGenrePersistentIDThe persistent identifier for a genre. Value is an
NSNumberobject containing auint64_t(unsigned long long).The value of the
MPMediaItemPropertyGenrePersistentIDidentifier persists across application launches and across syncs that do not change the sync status of the media item. The value is not guaranteed to persist across a sync/unsync/sync cycle.Can be used to build a media property predicate as described in MPMediaPropertyPredicate Class Reference.
Available in iOS 4.2 and later.
Declared in
MPMediaItem.h.MPMediaItemPropertyComposerPersistentIDThe persistent identifier for a composer. Value is an
NSNumberobject containing auint64_t(unsigned long long).The value of the
MPMediaItemPropertyComposerPersistentIDidentifier persists across application launches and across syncs that do not change the sync status of the media item. The value is not guaranteed to persist across a sync/unsync/sync cycle.Can be used to build a media property predicate as described in MPMediaPropertyPredicate Class Reference.
Available in iOS 4.2 and later.
Declared in
MPMediaItem.h.MPMediaItemPropertyPodcastPersistentIDThe persistent identifier for an audio podcast. Value is an
NSNumberobject containing auint64_t(unsigned long long).The value of the
MPMediaItemPropertyPodcastPersistentIDidentifier persists across application launches and across syncs that do not change the sync status of the media item. The value is not guaranteed to persist across a sync/unsync/sync cycle.Can be used to build a media property predicate as described in MPMediaPropertyPredicate Class Reference.
Available in iOS 4.2 and later.
Declared in
MPMediaItem.h.MPMediaItemPropertyMediaTypeThe media type of the media item. Value is an an
NSNumberobject representing anNSIntegerdata type. TheNSIntegervalue represents a bit field flag, or set of flags, from “Media Item Type Flags.”Can be used to build a media property predicate as described in MPMediaPropertyPredicate Class Reference.
Available in iOS 3.0 and later.
Declared in
MPMediaItem.h.MPMediaItemPropertyTitleThe title (or name) of the media item. This property is unrelated to the
MPMediaItemPropertyAlbumTitleproperty. Value is anNSStringobject.Can be used to build a media property predicate as described in MPMediaPropertyPredicate Class Reference.
Available in iOS 3.0 and later.
Declared in
MPMediaItem.h.MPMediaItemPropertyAlbumTitleThe title of an album, such as “Live On Mars”, as opposed to the title of an individual song on the album, such as “Crater Dance (radio edit)” (which you specify using the
MPMediaItemPropertyTitleproperty). Value is anNSStringobject.Can be used to build a media property predicate as described in MPMediaPropertyPredicate Class Reference.
Available in iOS 3.0 and later.
Declared in
MPMediaItem.h.MPMediaItemPropertyArtistThe performing artist(s) for a media item—which may vary from the primary artist for the album that a media item belongs to. For example, if the album artist is “Joseph Fable,” the artist for one of the songs in the album may be “Joseph Fable featuring Thomas Smithson”. Value is an
NSStringobject.Can be used to build a media property predicate as described in MPMediaPropertyPredicate Class Reference.
Available in iOS 3.0 and later.
Declared in
MPMediaItem.h.MPMediaItemPropertyAlbumArtistThe primary performing artist for an album as a whole. Value is an
NSStringobject.Can be used to build a media property predicate as described in MPMediaPropertyPredicate Class Reference.
Available in iOS 3.0 and later.
Declared in
MPMediaItem.h.MPMediaItemPropertyGenreThe musical or film genre of the media item. Value is an
NSStringobject.Can be used to build a media property predicate as described in MPMediaPropertyPredicate Class Reference.
Available in iOS 3.0 and later.
Declared in
MPMediaItem.h.MPMediaItemPropertyComposerThe musical composer for the media item. Value is an
NSStringobject.Can be used to build a media property predicate as described in MPMediaPropertyPredicate Class Reference.
Available in iOS 3.0 and later.
Declared in
MPMediaItem.h.MPMediaItemPropertyPlaybackDurationThe playback duration of the media item. Value is an
NSNumberobject representing a duration in seconds as anNSTimeInterval.Available in iOS 3.0 and later.
Declared in
MPMediaItem.h.MPMediaItemPropertyAlbumTrackNumberThe track number of the media item, for a media item that is part of an album. Value is an
NSNumberobject representing anNSUIntegerdata type.Available in iOS 3.0 and later.
Declared in
MPMediaItem.h.MPMediaItemPropertyAlbumTrackCountThe number of tracks in the album that contains the media item. Value is an
NSNumberobject representing anNSUIntegerdata type.For an audio streaming app, the system provides a default value of
1for this property.Available in iOS 3.0 and later.
Declared in
MPMediaItem.h.MPMediaItemPropertyDiscNumberThe disc number of the media item, for a media item that is part of a multi-disc album. Value is an
NSNumberobject representing anNSUIntegerdata type.Available in iOS 3.0 and later.
Declared in
MPMediaItem.h.MPMediaItemPropertyDiscCountThe number of discs in the album that contains the media item. Value is an
NSNumberobject representing anNSUIntegerdata type.Available in iOS 3.0 and later.
Declared in
MPMediaItem.h.MPMediaItemPropertyArtworkThe artwork image for the media item. Value is a media item image, described in MPMediaItemArtwork Class Reference.
Available in iOS 3.0 and later.
Declared in
MPMediaItem.h.MPMediaItemPropertyLyricsThe lyrics for the media item. Value is an
NSStringobject.Available in iOS 3.0 and later.
Declared in
MPMediaItem.h.MPMediaItemPropertyIsCompilationA Boolean value indicating whether the media item is part of a compilation (
YES), or not (NO). Corresponds to the the “Part of a compilation” checkbox in the Info tab in the Get Info dialog in iTunes. Value is anNSNumberobject representing aBOOLdata type.Available in iOS 3.0 and later.
Declared in
MPMediaItem.h.MPMediaItemPropertyReleaseDateThe date on which the media item was first publicly released. Value is an
NSDateobject.Available in iOS 4.0 and later.
Declared in
MPMediaItem.h.MPMediaItemPropertyBeatsPerMinuteThe number of musical beats per minute for the media item, corresponding to the “BPM” field in the Info tab in the Get Info dialog in iTunes. Value is an
NSNumberobject representing anNSUIntegerdata type.Available in iOS 4.0 and later.
Declared in
MPMediaItem.h.MPMediaItemPropertyCommentsTextual information about the media item, corresponding to the “Comments” field in in the Info tab in the Get Info dialog in iTunes. Value is an
NSStringobject.Available in iOS 4.0 and later.
Declared in
MPMediaItem.h.MPMediaItemPropertyAssetURLA URL pointing to the media item, from which an
AVAssetobject (or other URL-based AV Foundation object) can be created, with any options as desired. Value is anNSURLobject.The URL has the custom scheme of
ipod-library. For example, a URL might look like this:ipod-library://item/item.m4a?id=12345
Usage of the URL outside of the AV Foundation framework is not supported.
Available in iOS 4.0 and later.
Declared in
MPMediaItem.h.MPMediaItemPropertyIsCloudItemA Boolean value indicating whether the media item is an iCloud item (
YES), or not (NO). A media item is considered an iCloud item if it is available via iTunes Match and is not already stored on the device. Value is anNSNumberobject representing aBOOLdata type.Available in iOS 6.0 and later.
Declared in
MPMediaItem.h.
Podcast Item Property Keys
You obtain metadata for a podcast media item by calling the valueForProperty method with these property keys. So-called filterable properties can also be used to build media property predicates, as described in MPMediaPropertyPredicate Class Reference.
NSString *const MPMediaItemPropertyPodcastTitle; // filterable
Constants
MPMediaItemPropertyPodcastTitleThe title of a podcast, such as “This Martian Drudgery”, as opposed to the title of an individual episode of a podcast such as “Episode 12: Another Cold Day At The Pole” (which you specify using the
MPMediaItemPropertyTitleproperty). Value is anNSStringobject.Can be used to build a media property predicate as described in MPMediaPropertyPredicate Class Reference.
Available in iOS 3.0 and later.
Declared in
MPMediaItem.h.
User-Defined Property Keys
You obtain user-defined metadata for a media item by calling the valueForProperty: method with these property keys. User-defined properties cannot be used to build media property predicates.
NSString *const MPMediaItemPropertyPlayCount; NSString *const MPMediaItemPropertySkipCount; NSString *const MPMediaItemPropertyRating; NSString *const MPMediaItemPropertyLastPlayedDate; NSString *const MPMediaItemPropertyUserGrouping; NSString *const MPMediaItemPropertyBookmarkTime;
Constants
MPMediaItemPropertyPlayCountThe number of times the user has played the media item. Value is an
NSNumberobject representing anNSUIntegerdata type.Available in iOS 3.0 and later.
Declared in
MPMediaItem.h.MPMediaItemPropertySkipCountThe number of times the user has skipped playing the item. Value is an
NSNumberobject representing anNSUIntegerdata type.Available in iOS 3.0 and later.
Declared in
MPMediaItem.h.MPMediaItemPropertyRatingThe user-specified rating of the object in the range
[0...5], where a value of5indicates the most favorable rating. Value is anNSNumberobject representing anNSUIntegerdata type.Available in iOS 3.0 and later.
Declared in
MPMediaItem.h.MPMediaItemPropertyLastPlayedDateThe most recent calendar date on which the user played the media item. Value is an
NSDateobject.Available in iOS 3.0 and later.
Declared in
MPMediaItem.h.MPMediaItemPropertyUserGroupingCorresponds to the “Grouping” field in the Info tab in the Get Info dialog in iTunes. Value is an
NSStringobject.Available in iOS 4.0 and later.
Declared in
MPMediaItem.h.MPMediaItemPropertyBookmarkTimeThe user’s place in the media item the most recent time it was played. Value is an
NSNumberobject representing a duration in seconds as anNSTimeInterval.Available in iOS 6.0 and later.
Declared in
MPMediaItem.h.
© 2012 Apple Inc. All Rights Reserved. (Last updated: 2012-09-19)