Class

MPMediaPlaylist

A playable collection of related media items.

Declaration

class MPMediaPlaylist : MPMediaItemCollection

Overview

Each playlist has a name, a set of attributes, and a unique identifier that persists across application launches.

Users configure playlists using iTunes or by creating a playlist on the device. To your iOS application, playlists are read-only. To obtain playlists, configure a media query that is grouped by playlist. Each returned media item collection is a media playlist. The following code snippet illustrates this by logging playlist and song names to the Xcode debugger console:

let myPlaylistQuery = MPMediaQuery.playlists()
let playlists = myPlaylistQuery.collections
for playlist in playlists! {
    print(playlist.value(forProperty: MPMediaPlaylistPropertyName)!)
            
    let songs = playlist.items
    for song in songs {
        let songTitle = song.value(forProperty: MPMediaItemPropertyTitle)
        print("\t\t", songTitle!)
    }
}

The API for building a media query is described in MPMediaPropertyPredicate and MPMediaQuery. The methods for querying media playlist property values are described in MPMediaEntity.

Topics

Adding Media Items to a Playlist

func addItem(withProductID: String, completionHandler: ((Error?) -> Void)?)

Adds the item associated with the product identifier to the end of the playlist.

func add([MPMediaItem], completionHandler: ((Error?) -> Void)?)

Adds an array of media items to the end of the playlist.

Retrieving Information About a Playlist

var authorDisplayName: String?

App defined display name for the playlist.

var descriptionText: String?

User supplied text that describes the playlist.

var name: String?

The name of the playlist.

var persistentID: MPMediaEntityPersistentID

The persistent identifier for the playlist.

var playlistAttributes: MPMediaPlaylistAttribute

The attributes associated with the playlist

struct MPMediaPlaylistAttribute

Attributes define the type of playlist.

var seedItems: [MPMediaItem]?

The items seeded to generate the playlist; applies only to Genius playlists.

Property Keys

Playlist Property Keys

Keys that contain information about a playlist.

Relationships

Conforms To

See Also

Media Items and Playlists

class MPMediaItem

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

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