varunsrin
varunsrin

Reputation: 858

MPMedia Query to filter playlists for songs not working

I'm trying to retrieve playlists on iOS, but remove any non-music content. This was the original code, which was returning some video items.

MPMediaQuery *query = [[MPMediaQuery alloc] init];
[query addFilterPredicate:[MPMediaPropertyPredicate predicateWithValue:_playlistIdentifier forProperty:MPMediaPlaylistPropertyPersistentID]];
[query setGroupingType:MPMediaGroupingPlaylist];

So I changed it to:

MPMediaQuery *query = [[MPMediaQuery alloc] init];
[query addFilterPredicate:[MPMediaPropertyPredicate predicateWithValue:_playlistIdentifier forProperty:MPMediaPlaylistPropertyPersistentID]];
[query addFilterPredicate:[MPMediaPropertyPredicate predicateWithValue:[NSNumber numberWithInteger:MPMediaTypeMusic] forProperty:MPMediaItemPropertyMediaType]];
[query setGroupingType:MPMediaGroupingPlaylist];

However, no luck - one of our customers who has videos on the playlist (which are not available locally, just on iCloud) is still complaining that he can see the videos. Is there some reason that these non-music files are not being removed by this query?

Upvotes: 1

Views: 623

Answers (1)

iSankha007
iSankha007

Reputation: 395

As you mentioned in your question that videos that are not available on the device but stored on iCloud are showing in the playlist.So excluding icloud items may resolve the issue. so adding the filter as

[query addFilterPredicate:[MPMediaPropertyPredicate predicateWithValue:[NSNumber numberWithBool:NO] forProperty:MPMediaItemPropertyIsCloudItem]];

It will exclude the iCloud items which are not available right now.Hope it will work.

Upvotes: 1

Related Questions