Class

MPMediaItem

A collection of properties that represents a single item contained in the media library.

Overview

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 value(forProperty:) method along with the property keys described in this document. You can also access metadata in a batch fashion using the enumerateValues(forProperties:using:) method. Anytime the app accesses more than one property, enumerating over a set of property keys is more efficient than fetching each individual property. Both of these methods are defined in MPMediaEntity, the abstract superclass of MPMediaItemCollection, and described in MPMediaEntity.

You use attributes of media items to build media queries for searching the Media library. These attributes are described in MPMediaType, 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.

Topics

Media Item Properties

var albumArtist: String?

The primary performing artist for an album as a whole.

var albumArtistPersistentID: MPMediaEntityPersistentID

The persistent identifier for the primary performing artist for an album as a whole.

var albumPersistentID: MPMediaEntityPersistentID

The persistent identifier for an album.

var albumTitle: String?

The 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)”.

var albumTrackCount: Int

The number of tracks in the album that contains the media item.

var albumTrackNumber: Int

The track number of the media item, for a media item that is part of an album.

var artist: String?

The performing artist(s) for a media item—which may vary from the primary artist for the album that a media item belongs to.

var artistPersistentID: MPMediaEntityPersistentID

The persistent identifier for an artist.

var artwork: MPMediaItemArtwork?

The artwork image for the media item.

var assetURL: URL?

The URL pointing to the media item.

var beatsPerMinute: Int

The number of musical beats per minute for the media item.

var bookmarkTime: TimeInterval

The user’s place in the media item the most recent time it was played.

var isCloudItem: Bool

A Boolean value indicating whether the media item is an iCloud Music Library item.

var comments: String?

Textual information about the media item.

var isCompilation: Bool

A Boolean value indicating whether the media item is part of a compilation.

var composer: String?

The musical composer for the media item.

var composerPersistentID: MPMediaEntityPersistentID

The persistent identifier for a composer.

var dateAdded: Date

The date the item was added to the library.

var discCount: Int

The number of discs in the album that contains the media item.

var discNumber: Int

The disc number of the media item, for a media item that is part of a multi-disc album.

var isExplicitItem: Bool

A Boolean value that indicates whether the item has explicit (adult) lyrics or language.

var genre: String?

The musical or film genre of the media item.

var genrePersistentID: MPMediaEntityPersistentID

The persistent identifier for a genre.

var lastPlayedDate: Date?

The date a media item was last played.

var lyrics: String?

The lyrics for the media item.

var mediaType: MPMediaType

The media type of the media item.

var persistentID: MPMediaEntityPersistentID

The persistent identifier for the media item.

var playCount: Int

The number of times the user has played the media item.

var playbackDuration: TimeInterval

The playback duration of the media item.

var playbackStoreID: String

The non-library identifier for a media item.

var podcastPersistentID: MPMediaEntityPersistentID

The persistent identifier for an audio podcast.

var podcastTitle: String?

The 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”.

var hasProtectedAsset: Bool

A Boolean indicating whether the media item has a protected asset.

var rating: Int

The user-specified rating of the object in the range [0...5], where a value of 5 indicates the most favorable rating.

var releaseDate: Date?

The date on which the media item was first publicly released.

var skipCount: Int

The number of times the user has skipped playing the item.

var title: String?

The title (or name) of the media item.

var userGrouping: String?

Grouping information for the media item.

Obtaining Group Properties

class func persistentIDProperty(forGroupingType: MPMediaGrouping)

Obtains the persistent identifier key for a specified grouping type.

class func titleProperty(forGroupingType: MPMediaGrouping)

Obtains the title key for a specified grouping type.

Media Item Types and Keys

struct MPMediaType

The properties used to define the type for a media item.

General Media Item Property Keys

System defined properties used to obtain the metadata for a media item.

User-Defined Property Keys

Contains properties used to obtain user-defined metadata for a media item.

Relationships

Inherits From

See Also

Media Items and Playlists

class MPMediaItemArtwork

A graphical image, such as music album cover art, associated with a media item.

class MPMediaItemCollection

A sorted set of media items from the media library.

class MPMediaPlaylist

A playable collection of related media items.

class MPMediaPlaylistCreationMetadata

A set of attributes used to describe a playlist when the playlist is first created.

class MPMediaEntity

The abstract superclass for media items, media item collections, and media playlist instances.