iphoneipod

iPhone get all albums/artists


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!


Solution

  • Use a MPMediaQuery:

    MPMediaQuery *allAlbumsQuery = [MPMediaQuery albumsQuery];
    NSArray *allAlbumsArray = [allAlbumsQuery collections];
    

    The allItems array does now contain MPMediaItemCollections, grouping is done by album. Now you can walk through the arrays.

    for (MPMediaItemCollection *collection in allAlbumsArray) {
        MPMediaItem *item = [collection representativeItem];
    }