不能够从MPMediaItem(mp3歌曲)转换到NSData
我曾尝试以下代码:
这些是我的MPMediPickerController的委托方法:
- (void) mediaPicker: (MPMediaPickerController *) mediaPicker didPickMediaItems: (MPMediaItemCollection *) mediaItemCollection { // Dismiss the media item picker. [self dismissModalViewControllerAnimated: YES]; NSLog(@"%@ %d",mediaItemCollection,mediaItemCollection.count); NSArray *newMediaItem= [mediaItemCollection items]; MPMediaItem *item=[[newMediaItem objectAtIndex:0] retain]; [self uploadMusicFile:item]; }
这是我的自定义方法MPMediaItem NSData:
- (void) uploadMusicFile:(MPMediaItem *)song { NSURL *url = [song valueForProperty: MPMediaItemPropertyAssetURL]; AVURLAsset *songAsset = [AVURLAsset URLAssetWithURL: url options:nil]; AVAssetExportSession *exporter = [[AVAssetExportSession alloc] initWithAsset: songAsset presetName: AVAssetExportPresetPassthrough]; exporter.outputFileType = @"public.mpeg-4"; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *exportFile = [documentsDirectory stringByAppendingPathComponent: @"exported.mp4"]; NSURL *exportURL = [[NSURL fileURLWithPath:exportFile] retain]; exporter.outputURL = exportURL; [exporter exportAsynchronouslyWithCompletionHandler: ^{ NSData *data = [NSData dataWithContentsOfFile: [documentsDirectory stringByAppendingPathComponent: @"exported.mp4"]]; NSLog(@"%@",data); }]; }
我在NSlog中得到“null”。
我也检查这个post:
如何将nsdata转换为MPMediaitem的歌曲iOS Sdk
但没有得到解决scheme。
我正在使用xcode 4.6和ios 6.1。
有人可以告诉我这里有什么问题吗?