问题
I need to display a list of all of the playlists currently on the device. The problem is, on a device with iTunes Match turned on, any number of playlists could have zero items saved on the phone. Since (as far as I can tell) there's no reliable way to trigger an MPMediaItem download
when you're using AVAudioPlayer
, I'd like to filter out any playlists that don't have any local entries. Right now I can have it cycle through an individual playlist and strip songs that don't have an assetURL
, but this is waaaay too slow to do globally if the user has a lot of playlists. I tried filtering the entire music library to get playlists with
MPMediaQuery *songsQuery = [MPMediaQuery songsQuery];
[songsQuery addFilterPredicate:[MPMediaPropertyPredicate predicateWithValue:[NSNumber numberWithBool:NO] forProperty:MPMediaItemPropertyIsCloudItem]];
songsQuery.groupingType = MPMediaGroupingPlaylist;
However, when I cycle through the "collections" array it doesn't appear to filter any songs out at all. I'd try filtering by whether the song has an assetURL
, but of course you can't filter by that.
Does anyone have a reasonably fast way to pull this off? (Alternatively, has anyone figured out a decent way to trigger an MPMediaItem download
, since Apple has like no developer documentation on dealing with iTunes Match?)
回答1:
The MPMediaItemPropertyIsCloudItem
filter applies to MPMediaItem
s and not MPMediaItemCollection
s. So the collections
array does not filter any cloud items since it's an array of MPMediaItemCollection
s. But the items
array will filter cloud items since it's an array of MPMediaItem
s.
As of iOS 6, there is no public API to trigger a download of a cloud item through a third party app. The user will have to switch to the built-in Music app to do this.
来源:https://stackoverflow.com/questions/14490120/problems-with-mpmediaquery-and-itunes-match