Contents

MPMediaQuery

A query that specifies a set of media items from the device’s media library using a filter and a grouping type.

Declaration

class MPMediaQuery

Mentioned in

Overview

Filter and grouping types are both optional; an unqualified query matches the entire library.

A query has at most one grouping type. A query’s filter can consist of any number of media property predicates. You build filters using MPMediaPropertyPredicate objects, based on property keys described in MPMediaItem.

After creating and configuring a query, you use it to retrieve media items or media item collections. You can also use a query to retrieve an array of MPMediaQuerySection instances, useful for displaying the results of a query in the user interface of your app. See the itemSections and collectionSections properties.

This class includes several convenience constructors that each apply a grouping type and, in most cases, match a subset of the library. The following table summarizes the features of these constructors. See MPMediaItem for descriptions of the entries in the Filter column. See MPMediaGrouping for descriptions of the entries in the Grouping type column.

Constructor name

Matches entire library

Filter

Grouping type

Albums()

-

Music

Album

Artists()

-

Music

Artist

Audiobooks()

-

Audiobook

Title

Compilations()

-

Any with Mpmediaitempropertyiscompilation

Album

Composers()

Yes

Any

Composer

Genres()

Yes

Any

Genre

Playlists()

Yes

Any

Playlist

Podcasts()

-

Podcast

Podcasttitle

Songs()

-

Music

Title

Topics

Creating media queries

Configuring media queries

Performing media queries

Initializers

See Also

Media item queries