使用函数“addFilterPredicate”一次查询两首或更多歌曲。通过 MPMediaItemPropertyPersistentID
我的应用程序启动时会自动加载音乐播放列表。为此,我将歌曲 ID MPMediaItemPropertyPersistentID
存储到数据库中,并在应用下次启动时加载歌曲。主要代码如下:
MPMediaQuery *MPMediaSongQuery = [MPMediaQuery songsQuery];
MPMediaPropertyPredicate *iPodMusicSongPredicateiPodMusicSongPredicate = [MPMediaPropertyPredicate
predicateWithValue:[NSNumber numberWithUnsignedLongLong: songID]
forProperty:MPMediaItemPropertyPersistentID
comparisonType:MPMediaPredicateComparisonEqualTo];
[MPMediaSongQuery addFilterPredicate:iPodMusicSongPredicate];
NSArray *collections = MPMediaSongQuery.collections;
代码一首一首加载歌曲。我的问题是:在使用函数addFilterPredicate:
时,有没有办法通过MPMediaItemPropertyPercientID
一次查询两首或更多歌曲?谢谢。
My app loads a music playlist automatically when it starts up. In order to do this, I store the song IDs MPMediaItemPropertyPersistentID
to a database, and load the songs when the app is starting up next time. The main code is the following:
MPMediaQuery *MPMediaSongQuery = [MPMediaQuery songsQuery];
MPMediaPropertyPredicate *iPodMusicSongPredicateiPodMusicSongPredicate = [MPMediaPropertyPredicate
predicateWithValue:[NSNumber numberWithUnsignedLongLong: songID]
forProperty:MPMediaItemPropertyPersistentID
comparisonType:MPMediaPredicateComparisonEqualTo];
[MPMediaSongQuery addFilterPredicate:iPodMusicSongPredicate];
NSArray *collections = MPMediaSongQuery.collections;
The code loads song one by one. My question is: is there any way to query two or more songs by MPMediaItemPropertyPersistentID
at one time when using the function addFilterPredicate:
? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用多个 addFilterPredicate,它们将通过逻辑 AND 组合在一起。所以你只能减少第一个查询的结果,而不能扩展它。因此,您不允许对同一属性使用多个 addFilterPredicates。事实上,结果是未定义的,很可能最终会出现一个空集合。您正在寻找的是相同属性与逻辑或的组合。您可以像下面的伪代码所示来实现这一点:
...
If you use more than one addFilterPredicate they are combined with a logical AND. So you canm only reduce the results of the first query, but not extend it. As a consequence you are not allowed to use several addFilterPredicates for the same property. In fact the result is undefined and most likely will end up in an empty collection. What you are looking for is a combination of the same property with a logical OR. You can achieve this like depicted in the following pseudo-code:
...