0

The purpose of my code is to return an MPMediaPlaylist object, from a persistentID previously attained.

MPMediaPropertyPredicate *predicate = [MPMediaPropertyPredicate predicateWithValue:persistentID
                                                                       forProperty:MPMediaPlaylistPropertyPersistentID];
MPMediaQuery *query = [MPMediaQuery playlistsQuery];
[query addFilterPredicate:predicate];

The query.items are the tracks included in the playlist. What I want to be returned is the playlist itself. How do I get that?

Andrew
  • 7,693
  • 11
  • 43
  • 81

1 Answers1

4

See

https://developer.apple.com/library/ios/documentation/mediaplayer/reference/MPMediaPlaylist_ClassReference/Reference/Reference.html#//apple_ref/occ/cl/MPMediaPlaylist

for code that shows you how to get a playlist:

MPMediaQuery *myPlaylistsQuery = [MPMediaQuery playlistsQuery];
NSArray *playlists = [myPlaylistsQuery collections];

for (MPMediaPlaylist *playlist in playlists) {
    NSLog (@"%@", [playlist valueForProperty: MPMediaPlaylistPropertyName]);
    // ...
}

What you are actually getting is a list of songs (the items), but they are grouped by playlist. That is why asking for the query's collections gets you references to the MPMediaPlaylist objects you are after.

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • 1
    For me most important point is to get query object by [MPMediaQuery playlistsQuery] and then add predicate. Thanks! – AlexeyVMP May 22 '14 at 08:59