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!
To retrieve album artwork from the iTunes Store for your entire library, choose File > Library > Get Album Artwork.
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.
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.
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.
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];
}
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]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With