私は以下のコードを試してみました。iOS 6の問題NSDataにMPMediaItemを変換する
-(void)mediaItemToData : (MPMediaItem *) curItem
{
NSURL *url = [curItem 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 * myDocumentsDirectory = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;
NSString *exportFile = [myDocumentsDirectory stringByAppendingPathComponent:
@"exported.mp4"];
NSURL *exportURL = [NSURL fileURLWithPath:exportFile];
exporter.outputURL = exportURL;
// do the export
// (completion handler block omitted)
[exporter exportAsynchronouslyWithCompletionHandler:
^{
NSData *data = [NSData dataWithContentsOfFile: [myDocumentsDirectory
stringByAppendingPathComponent: @"exported.mp4"]];
DLog(@"Data %@",data);
}];
}
このコードは、iOS 5で細かい作業が、今のiOS 6
にAVAssetExportPresetPassthrough
でiOS6のためのすべての変更を進めています。 ???
を使用する理由は役に立つかもしれませんわからない、このリンクを見て試してみてくださいhttp://www.subfurther.com/blog/2010/07/19/from-iphone-media-library-to-pcm-samples-in-dozens-of-confounding-pentially-lossy-steps/ – Leena
@Leenaありがとうy私たちのリンクはこれを解決するのに役立ちます。 – Hitarth