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];
转载于:https://www.cnblogs.com/pengyingh/articles/2383510.html
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/110463.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...