Problems with MPMediaQuery and iTunes Match

ε祈祈猫儿з 提交于 2019-12-23 00:30:48

问题


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 MPMediaItems and not MPMediaItemCollections. So the collections array does not filter any cloud items since it's an array of MPMediaItemCollections. But the items array will filter cloud items since it's an array of MPMediaItems.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!