开发者

MPMediaQuery albumsQuery problem

Working on my new app called Covered, and I noti开发者_开发知识库ced a problem. I'm using it like this:

query = [[MPMediaQuery albumsQuery] retain]; [query setGroupingType:MPMediaGroupingAlbum];

Very simple thing, but after logging and seeing the results I noticed that it hides/skips all albums which don't have names. Is there a way to fix this? Has anyone else experienced this problem? Let me know ;)


Had the same problem. For example, I tried to get all Albums (including video) using something like this code

MPMediaQuery *query = [[MPMediaQuery alloc] init];
[query setGroupingType: MPMediaGroupingAlbum];
collections = [query collections];

but as you said, it missed the items that did not had any album information. My solution was to rebuild the album collections myself:

MPMediaQuery *query = [[MPMediaQuery alloc] init];
NSArray* a = [query items];
NSMutableArray* lc = [NSMutableArray array];
for (MPMediaItem* mp  in a) {
    NSString* atitle=[mp valueForProperty:MPMediaItemPropertyAlbumTitle];

    NSMutableArray* found = nil;
    for (NSMutableArray*l in lc) {
        NSString* ltitle=[l[0] valueForProperty:MPMediaItemPropertyAlbumTitle];

        if ((!atitle && !ltitle) || [atitle isEqualToString:ltitle]) {
            found = l;
            break;
        }
    }
    if (found) {
        [found addObject:mp];
    } else {
        [lc addObject:[NSMutableArray arrayWithObject:mp]];
    }
}
NSMutableArray* lcc = [NSMutableArray array];
for (NSMutableArray*l in lc) 
    [lcc addObject:[MPMediaItemCollection collectionWithItems:l]];
collections = [NSArray arrayWithArray:lcc];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜