2013-02-20 54 views
3

在我的应用程序中,我用魔杖来呈现媒体选择器,让用户选择1首歌曲,然后获取它的实际MP3(或任何其他格式,只要其可由其他iOS设备播放)文件。iOS iPod API - 获取实际的歌曲文件

如何完成? 我怎样才能用歌曲文件实际创建一个对象?

+0

为什么这个模样你试图找到一种方法来获得未经允许的MP3文件? – DiMono 2013-02-20 20:39:52

+0

我会得到用户的许可... – 2013-02-20 20:41:23

+0

事实上,我不想在这里做任何非法的事情(为了改变)。 – 2013-02-20 20:42:00

回答

6

我不知道为什么每个人都这么说bs有关从应用程序商店被拒绝。我将简要介绍如何开始。

-Present媒体选择器中打开用户的iPod:

MPMediaPickerController *pickerController = [[MPMediaPickerController alloc] initWithMediaTypes:MPMediaTypeMusic]; 
pickerController.prompt = NSLocalizedString(@"Choose Song", NULL); 
pickerController.allowsPickingMultipleItems = NO; 
pickerController.delegate = self; 
[self presentViewController:pickerController animated:YES completion:nil]; 
[pickerController release]; 

-Wait直到用户选择一首歌曲,并得到在mediaPicker委托回调:

- (void)mediaPicker:(MPMediaPickerController *)mediaPicker didPickMediaItems:(MPMediaItemCollection *)mediaItemCollection 
{ 
    MPMediaItem *theChosenSong = [[mediaItemCollection items]objectAtIndex:0]; 
    NSString *songTitle = [theChosenSong valueForProperty:MPMediaItemPropertyTitle]; 
    NSString *artist = [theChosenSong valueForProperty:MPMediaItemPropertyArtist]; 

    //then just get the assetURL 
    NSURL *assetURL = [theChosenSong valueForProperty:MPMediaItemPropertyAssetURL]; 
    AVURLAsset *songAsset = [AVURLAsset URLAssetWithURL:assetURL options:nil]; 

    //Now that you have this, either just write the asset (or part of) to disk, access the asset directly, send the written asset to another device etc 

}