iPhone get all albums/artists

前端 未结 3 1956
说谎
说谎 2021-02-04 11:48

does any of you have example code (or a link to it) of how to retrieve all music albums or artist from the iPod media library?

Thanks in advance!

3条回答
  •  死守一世寂寞
    2021-02-04 12:06

    Thanks for the answer, here is working sample code that prints out the albums and artists in case someone needs it:

    NSMutableString *outText = [[NSMutableString alloc] initWithString:@"Albums:"];
    [outText appendFormat:@"\r\n count:%i",[[[MPMediaQuery albumsQuery] collections] count]];
    for (MPMediaItemCollection *collection in [[MPMediaQuery albumsQuery] collections]) {
            [outText appendFormat:@"\r\n -%@",[[collection representativeItem] valueForProperty:MPMediaItemPropertyAlbumTitle]];
    }
    
    [outText appendString:@"\r\n\r\n Artist:"];
    
    for (MPMediaItemCollection *collection in [[MPMediaQuery artistsQuery] collections]) {
            [outText appendFormat:@"\r\n -%@",[[collection representativeItem] valueForProperty:MPMediaItemPropertyArtist]];
    }
    NSLog(@"%@",[outText autorelease]);
    

提交回复
热议问题