views:

280

answers:

1

Hi,

This code:

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

for( MPMediaItemCollection *c in songsByArtist ) {
 NSLog(@"artist %@ has %u songs",[[c representativeItem] valueForProperty:MPMediaItemPropertyArtist], [[c items]count]);
}

works as expected. But this code:

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

for( MPMediaItemCollection *c in songsByArtist ) {
 NSLog(@"artist %@ has %u songs",[[c representativeItem] valueForProperty:MPMediaItemPropertyArtist], [c count]);
}

always prints "1" for the number of songs. Can anyone else confirm this issue? It seems like a bug when looking at the documentation.

+1  A: 

Looks like you're counting the collections in that query rather than the songs inside of it.

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

for( MPMediaItemCollection *c in songsByArtist ) {
        NSLog(@"artist %@ has %u songs",[[c representativeItem] valueForProperty:MPMediaItemPropertyArtist], [[c items] count]);
}
El Chapitan