To obtain a sorted list of songs, configure a media query with the MPMediaGroupingTitle
key, or take advantage of the title key being the default for a media query.
Song是自己创建的一个类
A media item collection is a sorted set of media items (instances of the MPMediaItem
class) from the iPod library. Typically, you use this class by requesting an array of collections from a media query by way of its collections
property.
MPMediaQuery *myPlaylistsQuery = [MPMediaQuery songsQuery];
NSArray *playlists = [myPlaylistsQuery collections];
for (MPMediaItemCollection *playlist in playlists) {
NSArray *songs = [playlist items];
for (MPMediaItem *song in songs) {
Song *song1 = [[Song alloc] init];
song1.songName = [song valueForProperty: MPMediaItemPropertyTitle];
song1.remark = [song valueForKey:MPMediaItemPropertyPodcastTitle];
song1.singerName = [song valueForKey:MPMediaItemPropertyArtist];
song1.album = [song valueForKey:MPMediaItemPropertyAlbumTitle];
song1.songURL = [song valueForKey:MPMediaItemPropertyAssetURL];
[ipodAllSongsViewController.mySongArray addObject:song1];
[song1 release];
}
}