Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Number of Albums By Artists

That's my Question =)

MPMediaQuery *artistQuery = [MPMediaQuery artistsQuery];
NSArray *songsByArtist = [artistQuery collections];

How can I get the number of albums of each artists of the MPMediaItemCollections in songsByArtist ?

Exemple :

The Beatles 3 Albums

AC/DC 6 Albums

Thank You !!

like image 394
Jonathan Avatar asked May 15 '12 08:05

Jonathan


1 Answers

I get number of albums and songs for artist using predicate:

MPMediaPropertyPredicate *artistNamePredicate = [MPMediaPropertyPredicate predicateWithValue:@"ArtistName" forProperty:MPMediaItemPropertyArtist];
MPMediaQuery *myComplexQuery = [[MPMediaQuery alloc] init];
[myComplexQuery addFilterPredicate: artistNamePredicate];
NSInteger songCount = [[myComplexQuery collections] count]; //number of songs
myComplexQuery.groupingType = MPMediaGroupingAlbum;
NSInteger albumCount = [[myComplexQuery collections] count]; //number of albums
like image 130
Rinat Abidullin Avatar answered Sep 28 '22 07:09

Rinat Abidullin