这就是我打开媒体选择列表的代码
- (void)viewDidLoad
{
[super viewDidLoad];
player=[MPMusicPlayerController iPodMusicPlayer];
picker=[[MPMediaPickerController alloc] initWithMediaTypes:MPMediaTypeAnyAudio];
[picker setDelegate:self];
picker.prompt=@"Add an audio to application";
}
我还实施了其委托方法
- (void)mediaPicker:(MPMediaPickerController *)mediaPicker didPickMediaItems:(MPMediaItemCollection *)mediaItemCollection
{
/*I know only here I can get path but don't know how?
mediaItemCollection don't have such kind of properties or any
method to get selected file path.
So is there any other way to do so?
Note: I required this path, so that I can store it somewhere and can play it in future.
*/
}
答案 0 :(得分:3)
从mediaItemCollection.items数组的某个索引初始化MPMediaItem对象:
MPMediaItem *anItem = (MPMediaItem *)[mediaItemCollection.items objectAtIndex: row];
然后调用-valueForProperty:方法:
NSURL *assetURL = [anItem valueForProperty: MPMediaItemPropertyAssetURL];
您可以从此处描述的MPMediaItem获取其他属性:http://bit.ly/GGs3XI
查看“常规媒体项属性键”
希望这有帮助! 噬细胞