iOS Developer Library

Developer

MediaPlayer Framework Reference MPMediaPlaylist Class Reference

Options
Deployment Target:

On This Page
Language:

MPMediaPlaylist

Import Statement


Swift

import MediaPlayer

Objective-C

@import MediaPlayer;

Availability


Available in iOS 3.0 and later.

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.

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

    Declaration

    Swift

    struct MPMediaPlaylistAttribute : RawOptionSetType { init(_ rawValue: UInt) init(rawValue rawValue: UInt) static var None: MPMediaPlaylistAttribute { get } static var OnTheGo: MPMediaPlaylistAttribute { get } static var Smart: MPMediaPlaylistAttribute { get } static var Genius: MPMediaPlaylistAttribute { get } }

    Objective-C

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

    Constants

    • None

      MPMediaPlaylistAttributeNone

      If set, the playlist has no attributes.

      Available in iOS 3.0 and later.

    • OnTheGo

      MPMediaPlaylistAttributeOnTheGo

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

      Available in iOS 3.0 and later.

    • Smart

      MPMediaPlaylistAttributeSmart

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

      Available in iOS 3.0 and later.

    • Genius

      MPMediaPlaylistAttributeGenius

      If set, the playlist is a Genius playlist.

      Available in iOS 3.0 and later.

    Import Statement

    Objective-C

    @import MediaPlayer;

    Swift

    import MediaPlayer

    Availability

    Available in iOS 3.0 and later.

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

    Declaration

    Swift

    let MPMediaPlaylistPropertyPersistentID: String let MPMediaPlaylistPropertyName: String let MPMediaPlaylistPropertyPlaylistAttributes: String let MPMediaPlaylistPropertySeedItems: String

    Objective-C

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

    Constants

    • MPMediaPlaylistPropertyPersistentID

      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.

    • MPMediaPlaylistPropertyName

      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.

    • MPMediaPlaylistPropertyPlaylistAttributes

      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.

    • MPMediaPlaylistPropertySeedItems

      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.