Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone get all albums/artists

Tags:

iphone

ipod

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!

like image 400
Daniel Avatar asked Oct 15 '10 09:10

Daniel


People also ask

How do you get all album artwork on iTunes?

To retrieve album artwork from the iTunes Store for your entire library, choose File > Library > Get Album Artwork.

How do you play all albums on an artist on Apple Music?

Select Artists, if it is not selected already and all the Artists in your library are shown on the left of the screen on the ipad or below on the iPhone. Simply click the photo to left of artists name and it will play all the music by that artist.

How do I get a list of artists on Apple Music?

Just typing an artist's name is the search box generally brings up a drop down menu - the top has a choice to select My Music or Apple Music - and then generally a listing of artists with that or similar names.

How do I see all songs by an artist on my iPhone?

Open the music app, under the Recently Added, you can find a title that you can change. Set it to Artists. You will see an alphabetical list of artists. Then tap on the one artist and their list of songs or if you have multiple albums, their list of albums and songs will appear.


2 Answers

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];
}
like image 124
Björn Marschollek Avatar answered Sep 21 '22 14:09

Björn Marschollek


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]);
like image 42
Daniel Avatar answered Sep 20 '22 14:09

Daniel