1

I wants to get multiple artists tracks from iPod Library . The following code allow me to get specific artist tracks like -

MPMediaQuery *query = [[MPMediaQuery alloc] init];
    [query addFilterPredicate: [MPMediaPropertyPredicate
                                predicateWithValue:@"Lady Gaga"
                                forProperty: MPMediaItemPropertyArtist]];
 [query setGroupingType: MPMediaGroupingAlbum];

    NSArray *albums = [query collections];

is it possible to get multiple artists tracks like Lady Gaga & Akon tracks only single query predicateWithValue sepearted by ; OR /
Example-

[query addFilterPredicate: [MPMediaPropertyPredicate
                                    predicateWithValue:@"Lady Gaga/ Akon"
                                    forProperty: MPMediaItemPropertyArtist]];

Please help me how to meet my requirement .

Anupam Mishra
  • 3,408
  • 5
  • 35
  • 63

1 Answers1

0

You could use the aggregate operator IN (e.g. @"attribute IN %@", aCollection)and filter the whole collections array with an 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];
Teo
  • 3,394
  • 11
  • 43
  • 73