本文介绍了如何获取使用MPMediaPickerController选择的文件的路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我打开媒体选择器列表的代码

- (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.
    */
}

推荐答案

从mediaItemCollection.items数组的某些索引初始化MPMediaItem对象:

Initialize a MPMediaItem object from some index of the mediaItemCollection.items array:

MPMediaItem *anItem = (MPMediaItem *)[mediaItemCollection.items objectAtIndex: row];

然后调用-valueForProperty:方法:

Then call the -valueForProperty: method:

NSURL *assetURL = [anItem valueForProperty: MPMediaItemPropertyAssetURL];

您还可以从此处描述的MPMediaItem获得其他属性:http://bit.ly/GGs3XI

There are other properties that you can get from the MPMediaItem described here:http://bit.ly/GGs3XI

在常规媒体项目属性键"下查看

Look under "General Media Item Property Keys"

希望这会有所帮助!Tams

Hope this helps!Tams

这篇关于如何获取使用MPMediaPickerController选择的文件的路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-11 06:11