MPMediaPlaylist Class Reference

Inherits from
Conforms to
Framework
/System/Library/Frameworks/MediaPlayer.framework
Availability
Available in iOS 3.0 and later.
Companion guide
Declared in
MPMediaPlaylist.h

Overview

A media playlist is a playable collection of related media items. (Media items are described in MPMediaItem Class Reference.) Each playlist has a name, a set of attributes, and a unique identifier that persists across application launches.

Users configure playlists using iTunes on the desktop or by creating an on-the-go 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:

MPMediaQuery *myPlaylistsQuery = [MPMediaQuery playlistsQuery];
NSArray *playlists = [myPlaylistsQuery collections];
 
for (MPMediaPlaylist *playlist in playlists) {
    NSLog (@"%@", [playlist valueForProperty: MPMediaPlaylistPropertyName]);
 
    NSArray *songs = [playlist items];
    for (MPMediaItem *song in songs) {
        NSString *songTitle =
            [song valueForProperty: MPMediaItemPropertyTitle];
        NSLog (@"\t\t%@", songTitle);
    }
}

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

Constants

Playlist Attribute Flags

Playlist attributes, used as possible values for the MPMediaPlaylistPropertyPlaylistAttributes property.

enum {
   MPMediaPlaylistAttributeNone    = 0,
   MPMediaPlaylistAttributeOnTheGo = (1 << 0),
   MPMediaPlaylistAttributeSmart   = (1 << 1),
   MPMediaPlaylistAttributeGenius  = (1 << 2)
};
typedef NSInteger MPMediaPlaylistAttribute;
Constants
MPMediaPlaylistAttributeNone

If set, the playlist has no attributes.

Available in iOS 3.0 and later.

Declared in MPMediaPlaylist.h.

MPMediaPlaylistAttributeOnTheGo

If set, the playlist was created on a device rather than synced from iTunes.

Available in iOS 3.0 and later.

Declared in MPMediaPlaylist.h.

MPMediaPlaylistAttributeSmart

If set, the playlist is a “smart” playlist, whose members are determined by user-specified rules.

Available in iOS 3.0 and later.

Declared in MPMediaPlaylist.h.

MPMediaPlaylistAttributeGenius

If set, the playlist is a Genius playlist.

Available in iOS 3.0 and later.

Declared in MPMediaPlaylist.h.

Playlist Property Keys

Use these keys with the canFilterByProperty: and valueForProperty: methods to obtain information about a playlist. Properties described as “filterable” can be used to build media property predicates (see MPMediaPropertyPredicate Class Reference).

NSString *const MPMediaPlaylistPropertyPersistentID;        // filterable
NSString *const MPMediaPlaylistPropertyName;                // filterable
NSString *const MPMediaPlaylistPropertyPlaylistAttributes;  // filterable
NSString *const MPMediaPlaylistPropertySeedItems;
Constants
MPMediaPlaylistPropertyPersistentID

The persistent identifier for the playlist. Value is an NSNumber object containing a UInt64_t (unsigned long long).

Can be used to build a media property predicate as described in MPMediaQuery Class Reference.

Available in iOS 3.0 and later.

Declared in MPMediaPlaylist.h.

MPMediaPlaylistPropertyName

The name of the playlist. Value is an NSString object.

Can be used to build a media property predicate as described in MPMediaQuery Class Reference.

Available in iOS 3.0 and later.

Declared in MPMediaPlaylist.h.

MPMediaPlaylistPropertyPlaylistAttributes

The attributes associated with the playlist. Value is an NSNumber object containing an NSInteger data type. Fields in the NSInteger identify the attributes of the playlist. A playlist may have any combination of attributes described in “Playlist Attribute Flags.”

Can be used to build a media property predicate as described in MPMediaQuery Class Reference.

Available in iOS 3.0 and later.

Declared in MPMediaPlaylist.h.

MPMediaPlaylistPropertySeedItems

The items seeded to generate the playlist; applies only to Genius playlists. Value is an NSArray object containing one or more MPMediaItem objects.

Value is nil for playlists that do not have the MPMediaPlaylistAttributeGenius flag set.

Available in iOS 3.0 and later.

Declared in MPMediaPlaylist.h.