<!--
{
  "documentType" : "article",
  "framework" : "MediaPlayer",
  "identifier" : "/documentation/MediaPlayer/using-filters-to-create-specialized-queries",
  "metadataVersion" : "0.1.0",
  "role" : "article",
  "title" : "Using filters to create specialized queries"
}
-->

# Using filters to create specialized queries

Add a filter set to a query before populating a music player queue.

## Discussion

Creating a queue and adding it to a music player is a straightforward task. You populate the music player queue by creating a basic query and searching the user’s music library for items that match the query. However, you can create filters and add them at query creation to refine the player’s music queue. Filter for an album, artist, song, or any of a variety of other options. For a list of keys you can use as filters, see [General media item property keys](/documentation/MediaPlayer/general-media-item-property-keys).

### Create one or more filters

You need to create a new filter for each item you want to filter on. For example, if you want to filter for a specific album and all songs that contain a certain word from that album, you need two separate filters.

```swift
let albumTitleFilter =
    MPMediaPropertyPredicate(value: "Album Title",
                             forProperty: MPMediaItemPropertyAlbumTitle,
                             comparisonType: .equalTo)

let songTitleFilter =
    MPMediaPropertyPredicate(value: "Song Title",
                             forProperty: MPMediaItemPropertyTitle,
                             comparisonType: .contains)
```

### Combine the filters into a filter set

Combine the filters into a filter set before you assign it to a query.

```swift
let filterSet = Set([albumTitleFilter, songTitleFilter])
```

### Create a query using the filter set

Create a new query using the newly created filter set, and set the music player’s queue.

```swift
let query = MPMediaQuery(filterPredicates: filterSet)
musicPlayer.setQueue(with: query)
```

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)