【问题标题】:is there any way to search multiple artists tracks from iPod Library at a time .有没有办法一次从 iPod 库中搜索多个艺术家的曲目。
【发布时间】:2015-06-03 07:40:13
【问题描述】:

我想从 iPod Library 中获取多个艺术家的曲目。以下代码允许我获取特定的艺术家曲目,例如 -

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]];

请帮助我如何满足我的要求。

【问题讨论】:

    标签: ios ipod mpmediaquery mpmedialibrary


    【解决方案1】:

    您可以使用聚合运算符IN(例如@"attribute IN %@", aCollection)并使用NSPredicate 过滤整个collections 数组:

    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];
    

    【讨论】:

    • 嗨,skyddict,我使用了你的代码,但没有得到任何结果,而不是我的设备中有这些艺术家的踪迹。
    猜你喜欢
    • 2017-04-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多