当我组合两个m4a音频文件并导出这个文件时,这总是会给我失败。我在这里得到了同样的问题,我尝试了每个人的答案,但没有一个对我有效。
NSString* documentsDirectory= [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString* myDocumentPath= [documentsDirectory stringByAppendingPathComponent:@"merge_audio.mp4"];
NSURL *url = [NSURL fileURLWithPath:myDocumentPath];//[[NSURL alloc] initFileURLWithPath: myDocumentPath];
NSLog(@"%@",url);
//Check if the file exists then delete the old file to save the merged video file.
if([[NSFileManager defaultManager]fileExistsAtPath:myDocumentPath])
{
[[NSFileManager defaultManager]removeItemAtPath:myDocumentPath error:nil];
}
AVAssetExportSession *exporter=[[AVAssetExportSession alloc] initWithAsset:composition presetName:AVAssetExportPresetAppleM4A];
exporter.outputURL=url;
exporter.outputFileType=AVFileTypeAppleM4A;
[exporter exportAsynchronouslyWithCompletionHandler:^{
switch([exporter status])
{
case AVAssetExportSessionStatusFailed:
NSLog(@"Failed to export audio");
break;
case AVAssetExportSessionStatusCancelled:
NSLog(@"export cancelled");
break;
case AVAssetExportSessionStatusCompleted:
//Here you go you have got the merged video :)
NSLog(@"Merging completed");
break;
default:
break;
}
}];发布于 2015-12-11 20:03:46
您可以在AVAssetExportSession的error property中找到所需的解释,只需记录下来即可。
https://stackoverflow.com/questions/34221833
复制相似问题