我通过以下代码从 MPMediaPickerController 导入了一个 .mp3 文件:-
MPMediaPickerController *mediaPicker = [[MPMediaPickerController alloc] initWithMediaTypes: MPMediaTypeAny];
mediaPicker.delegate = self;
mediaPicker.allowsPickingMultipleItems = YES;
mediaPicker.prompt = @"Select songs to play";
[self presentModalViewController:mediaPicker animated:YES];
[mediaPicker release];
现在我想将选定的 .mp3 文件转换为 NSDATA 以便我可以将该 nsdata 上传到服务器:-
- (void) mediaPicker: (MPMediaPickerController *) mediaPicker didPickMediaItems: (MPMediaItemCollection *) mediaItemCollection
{
MPMusicPlayerController *musicPlayer = [MPMusicPlayerController iPodMusicPlayer];
[musicPlayer setQueueWithItemCollection: mediaItemCollection];
NSLog(@"==>%@",musicPlayer);
[musicPlayer play];
[self dismissModalViewControllerAnimated: YES];
}
主要问题是如何将音乐文件转换为 NSDATA 或任何其他格式,通过它我可以将其上传到服务器。然后可以在下载与音频文件相同的文件后轻松使用它