1、获取iPod歌曲列表:
[[MPMediaPickerController alloc] initWithMediaTypes: MPMediaTypeMusic];
picker.delegate = self;
picker.allowsPickingMultipleItems = YES;
picker.prompt = @"新增歌曲";
[self presentModalViewController: picker animated: YES];
[picker release];
回调方法:
- (void) mediaPicker: (MPMediaPickerController *) mediaPicker didPickMediaItems: (MPMediaItemCollection *) mediaItemCollection
mediaItemCollection 就是我们所需要的歌曲的列表
(2)通过MPMediaQuery
MPMediaQuery *query = [MPMediaQuery playlistsQuery];//初始话类型 枚举playlistsQuery
NSArray *tempArray = [[NSArray alloc] initWithArray:[query items]];
tempArray 就是我们所需要的列表
2、歌曲的播放
(1)、通过MPMusicPlayerController 播放
NSArray *tempArray = [[NSArray alloc] initWithArray:[query items]];
_mediaCollection = [[MPMediaItemCollection alloc]initWithItems:tempArray];
[_mediaCollection retain];
_player = [MPMusicPlayerController applicationMusicPlayer]; //初始化播放器;
[_player setQueueWithItemCollection:_mediaCollection];
[_player setRepeatMode:MPMusicRepeatModeAll];
[musicPlayer.player setNowPlayingItem:[[musicPlayer.mediaCollectionitems]objectAtIndex:indexPath.row]];
[musicPlayer play];
(2) AVPlayer
NSURL *url = [[[musicPlayer.mediaCollection items] objectAtIndex: indexPath.row]valueForProperty:MPMediaItemPropertyAssetURL];
AVPlayer *player = [[AVPlayer alloc] initWithURL:url];
[player play];