我想从iPod库中获取多个艺术家曲目。以下代码允许我获取特定的艺术家曲目,如 -
MPMediaQuery *query = [[MPMediaQuery alloc] init];
[query addFilterPredicate: [MPMediaPropertyPredicate
predicateWithValue:@"Lady Gaga"
forProperty: MPMediaItemPropertyArtist]];
[query setGroupingType: MPMediaGroupingAlbum];
NSArray *albums = [query collections];
是否可以获得多个艺术家的曲目,如 Lady Gaga& Akon 仅跟踪单个查询 predicateWithValue ;或/
示例 -
[query addFilterPredicate: [MPMediaPropertyPredicate
predicateWithValue:@"Lady Gaga/ Akon"
forProperty: MPMediaItemPropertyArtist]];
请帮助我如何满足我的要求。
答案 0 :(得分:0)
您可以使用汇总运算符IN
(例如@"attribute IN %@", aCollection
)并使用collections
过滤整个NSPredicate
数组:
NSArray *artists = @["Lady Gaga", @"Justin Bieber", @"Selena Gomez"];
MPMediaQuery *query = [[MPMediaQuery alloc] init];
[query setGroupingType: MPMediaGroupingAlbum];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"%@ IN %@", MPMediaItemPropertyArtist, artists];
NSArray *albums = [[query collections] filteredArrayUsingPredicate:predicate];