在我的应用程序中,我使用 AVAssetExportSession 组合两个音频文件,它在早期的 ios 版本中运行良好。但在 ios5 设备中它不起作用。我得到的是一个错误
AVAssetExportSessionStatusFailed: Error Domain=AVFoundationErrorDomain Code=-11820 "Cannot Complete Export" UserInfo=0x1df1c0 {NSLocalizedRecoverySuggestion=Try exporting again., NSLocalizedDescription=Cannot Complete Export}
我用于导出的代码如下
有没有人遇到过同样的问题?请提出您宝贵的建议。我迫切需要解决这个问题..
//Export function to export the combined audios as one.
-(void)exportAudioFile:(AVComposition*)combinedComposition
{
AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:combinedComposition
presetName:AVAssetExportPresetPassthrough];
NSArray *presets =[AVAssetExportSession exportPresetsCompatibleWithAsset:combinedComposition];
NSLog(@"presets======%@",presets);
NSLog (@"can export: %@", exportSession.supportedFileTypes);
NSArray *dirs = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectoryPath = [dirs objectAtIndex:0];
exportPath = [documentsDirectoryPath stringByAppendingPathComponent:@"CombinedNew.m4a"];
[[NSFileManager defaultManager] removeItemAtPath:exportPath error:nil];
exportURL = [NSURL fileURLWithPath:exportPath];
exportSession.outputURL = exportURL;
exportSession.outputFileType = @"com.apple.m4a-audio";
exportSession.shouldOptimizeForNetworkUse = YES;
[exportSession exportAsynchronouslyWithCompletionHandler:^{
NSLog (@"i is in your block, exportin. status is %d",
exportSession.status);
switch (exportSession.status)
{
case AVAssetExportSessionStatusFailed:
{
// log error to text view
NSError *exportError = exportSession.error;
DEBUG_LOG(@"AVAssetExportSessionStatusFailed: %@", exportError);
[self enableUI];
break;
}
case AVAssetExportSessionStatusCompleted:
{
DEBUG_LOG(@"AVAssetExportSessionStatusCompleted");
DEBUG_LOG(@"Completed export");
exportSuccess = YES;
if (recorderFilePath)
{
NSError *finalurlError;
[[NSFileManager defaultManager]removeItemAtPath:recorderFilePath error:&finalurlError];
finalurlError = nil;
[[NSFileManager defaultManager]copyItemAtPath:[exportURL path] toPath:recorderFilePath error:&finalurlError];
}
isExported = YES;
fileUrl = [NSURL fileURLWithPath:recorderFilePath];
[self performSelectorInBackground:@selector(updatePlayerForUrl:) withObject:fileUrl];
break;
}
case AVAssetExportSessionStatusUnknown:
{
DEBUG_LOG(@"AVAssetExportSessionStatusUnknown");
break;
}
case AVAssetExportSessionStatusExporting:
{
DEBUG_LOG(@"AVAssetExportSessionStatusExporting");
break;
}
case AVAssetExportSessionStatusCancelled:
{
DEBUG_LOG(@"AVAssetExportSessionStatusCancelled");
break;
}
case AVAssetExportSessionStatusWaiting:
{
DEBUG_LOG(@"AVAssetExportSessionStatusWaiting");
break;
}
default:
{
DEBUG_LOG(@"didn't get export status");
break;
}
};
}];
[exportSession release];
}