MPMediaQuery和iTunes Match的问题 [英] Problems with MPMediaQuery and iTunes Match

查看:167
本文介绍了MPMediaQuery和iTunes Match的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要显示设备上当前所有播放列表的列表.问题是,在启用了iTunes Match的设备上,任意数量的播放列表可能会将零个项目保存在手机上.由于(据我所知),当您使用AVAudioPlayer时,没有可靠的方法来触发MPMediaItem download,因此我想过滤掉没有本地条目的所有播放列表.现在,我可以让它在单个播放列表中循环播放,并剥离没有assetURL的歌曲,但是如果用户有很多播放列表,那么这样做就太慢了,无法在全局范围内播放.我尝试过滤整个音乐库以获取播放列表

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;

但是,当我循环浏览"collections"数组时,它似乎根本无法过滤掉任何歌曲.我会尝试根据歌曲是否包含assetURL进行过滤,但是您当然不能对此进行过滤.

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.

有人能以一种相当快速的方式实现这一目标吗? (或者,有没有人想出一种触发MPMediaItem download的不错的方法,因为苹果公司不喜欢任何有关处理iTunes Match的开发人员文档?)

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?)

推荐答案

MPMediaItemPropertyIsCloudItem过滤器适用于MPMediaItem s,而不适用于MPMediaItemCollection s.因此collections数组不会过滤任何云项目,因为它是MPMediaItemCollection的数组.但是items数组将过滤云项目,因为它是MPMediaItem s的数组.

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.

从iOS 6开始,没有公共API可以触发通过第三方应用程序下载云项目.用户必须切换到内置的音乐"应用程序才能执行此操作.

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.

这篇关于MPMediaQuery和iTunes Match的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆