iOS Developer Library

Developer

MediaPlayer Framework Reference MPMediaItemCollection Class Reference

Options
Deployment Target:

On This Page
Language:

MPMediaItemCollection

A media item collection is a sorted set of media items (instances of the MPMediaItem class) from the iPod library. Typically, you use this class by requesting an array of collections from a media query by way of its collections property. Media queries are described in MPMediaQuery Class Reference.

The grouping type for the media query determines the arrangement of the media items you obtain. You also use the media query collections property to obtain synced playlists, as described in MPMediaPlaylist Class Reference.

A media item collection 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. The 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.

Inheritance


Import Statement


Swift

import MediaPlayer

Objective-C

@import MediaPlayer;

Availability


Available in iOS 3.0 and later.
  • Creates a media item collection by copying an array of media items.

    Declaration

    Objective-C

    + (MPMediaItemCollection *)collectionWithItems:(NSArray *)items

    Parameters

    items

    The array of media items you are assigning to the media item collection.

    Return Value

    A media item collection.

    Import Statement

    Objective-C

    @import MediaPlayer;

    Availability

    Available in iOS 3.0 and later.

  • init(items:) - initWithItems: Designated Initializer

    Initializes a media item collection with an array of media items.

    Declaration

    Swift

    init!(items items: [AnyObject]!)

    Objective-C

    - (instancetype)initWithItems:(NSArray *)items

    Parameters

    items

    The array of items you are assigning to the media item collection.

    Import Statement

    Objective-C

    @import MediaPlayer;

    Swift

    import MediaPlayer

    Availability

    Available in iOS 3.0 and later.

  • items items Property

    The media items in a media item collection.

    Declaration

    Swift

    var items: [AnyObject]! { get }

    Objective-C

    @property(nonatomic, readonly) NSArray *items

    Import Statement

    Objective-C

    @import MediaPlayer;

    Swift

    import MediaPlayer

    Availability

    Available in iOS 3.0 and later.

  • A media item whose properties are representative of the other media items in a collection.

    Declaration

    Swift

    var representativeItem: MPMediaItem! { get }

    Objective-C

    @property(nonatomic, readonly) MPMediaItem *representativeItem

    Discussion

    The media items in a collection typically share common property values, owing to how the collection was built. For example, if you build a collection based on a predicate that uses the MPMediaItemPropertyArtist property, all items in the collection share the same artist name. You can use the representativeItem property to efficiently obtain values for such common properties—often more efficiently than fetching an item from the items array.

    Import Statement

    Objective-C

    @import MediaPlayer;

    Swift

    import MediaPlayer

    Availability

    Available in iOS 3.0 and later.

  • count count Property

    The number of media items in a collection.

    Declaration

    Swift

    var count: Int { get }

    Objective-C

    @property(nonatomic, readonly) NSUInteger count

    Discussion

    In some cases, using this property is more efficient than fetching the items array and asking for the count.

    Import Statement

    Objective-C

    @import MediaPlayer;

    Swift

    import MediaPlayer

    Availability

    Available in iOS 3.0 and later.

  • The types of the media items in a collection.

    Declaration

    Swift

    var mediaTypes: MPMediaType { get }

    Objective-C

    @property(nonatomic, readonly) MPMediaType mediaTypes

    Discussion

    The media item types are listed in the Media Item Type Flags enumeration in MPMediaItem Class Reference.

    Import Statement

    Objective-C

    @import MediaPlayer;

    Swift

    import MediaPlayer

    Availability

    Available in iOS 3.0 and later.