How to get path of file selected using MPMediaPickerController?

狂风中的少年 提交于 2019-12-11 02:48:57

问题


This is how I've code to open media picker list

- (void)viewDidLoad
{
    [super viewDidLoad];

    player=[MPMusicPlayerController iPodMusicPlayer];

    picker=[[MPMediaPickerController alloc] initWithMediaTypes:MPMediaTypeAnyAudio];

    [picker setDelegate:self];

    picker.prompt=@"Add an audio to application";
}

I've also implemented its delegate method

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

回答1:


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

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

Then call the -valueForProperty: method:

NSURL *assetURL = [anItem valueForProperty: MPMediaItemPropertyAssetURL];

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

Look under "General Media Item Property Keys"

Hope this helps! Tams



来源:https://stackoverflow.com/questions/9817638/how-to-get-path-of-file-selected-using-mpmediapickercontroller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!