MPMediaItemCollection Class Reference

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

Overview

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.

Tasks

Creating a Media Item Collection

Using a Media Item Collection

Properties

count

The number of media items in a collection.

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

Availability
  • Available in iOS 3.0 and later.
Related Sample Code
Declared In
MPMediaItemCollection.h

items

The media items in a media item collection.

@property (nonatomic, readonly) NSArray *items;
Availability
  • Available in iOS 3.0 and later.
Related Sample Code
Declared In
MPMediaItemCollection.h

mediaTypes

The types of the media items in a collection.

@property (nonatomic, readonly) MPMediaType mediaTypes;
Discussion

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

Availability
  • Available in iOS 3.0 and later.
Declared In
MPMediaItemCollection.h

representativeItem

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

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

Availability
  • Available in iOS 3.0 and later.
Declared In
MPMediaItemCollection.h

Class Methods

collectionWithItems:

Creates a media item collection by copying an array of media items.

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

Availability
  • Available in iOS 3.0 and later.
Related Sample Code
Declared In
MPMediaItemCollection.h

Instance Methods

initWithItems:

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

- (id) initWithItems: (NSArray *) items;
Parameters
items

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

Availability
  • Available in iOS 3.0 and later.
Declared In
MPMediaItemCollection.h