2012-03-22 67 views
2

這是我怎麼樣了代碼來打開媒體選擇列表如何獲取使用MPMediaPickerController選擇的文件的路徑?

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    player=[MPMusicPlayerController iPodMusicPlayer]; 

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

    [picker setDelegate:self]; 

    [email protected]"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. 
    */ 
} 

回答

3

從mediaItemCollection的一些指標初始化MPMediaItem對象.items array:

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

然後調用-valueForProperty:方法:

NSURL *assetURL = [anItem valueForProperty: MPMediaItemPropertyAssetURL]; 

還有其他的屬性,你可以從這裏MPMediaItem描述獲得:HTTP://bit.ly/GGs3XI

看一般的媒體項目屬性鍵下」 「

希望這有助於! Tams

+0

NSData * someData = [NSData dataWithContentsOfURL:yourURLVariable]; – tams 2013-04-24 20:38:56

相關問題