Bug in iPhone Library Access?

979 views Asked by At

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

There are 1 answers

0
El Chapitan On

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