在我的应用程序中,我想展示媒体选择器,让用户选择一首歌曲,然后获取它的实际 MP3(或任何其他格式,只要它可由其他 iOS 设备播放)文件。
怎么可能实现?我如何才能用歌曲文件实际创建一个对象?
我不知道为什么每个人都说这么多关于被应用商店拒绝的废话。我将为您简要介绍如何开始。
- 呈现媒体选择器以打开用户的 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];
- 等到用户选择一首歌曲并在 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
}