Sid*_*rth 1 iphone objective-c avfoundation ios5 avassetexportsession
在我的应用程序中,我使用AVAssetExportSession组合两个音频文件,它在早期的ios版本中工作正常.但在ios5设备中它无法正常工作.我得到的是一个错误
AVAssetExportSessionStatusFailed: Error Domain=AVFoundationErrorDomain Code=-11820 "Cannot Complete Export" UserInfo=0x1df1c0 {NSLocalizedRecoverySuggestion=Try exporting again., NSLocalizedDescription=Cannot Complete Export}
Run Code Online (Sandbox Code Playgroud)
我用于导出的代码如下所示
有没有人遇到过同样的问题?请提供宝贵的建议.我迫切需要解决这个问题..
//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];
}
Run Code Online (Sandbox Code Playgroud)
我为自己整理了答案,并希望与遇到同样问题的其他人分享.
问题是由于某种原因,AVAssetExportPresetPassthrough在ios5中无法正常工作.用它代替AVAssetExportPresetAppleM4A解决问题.
但现在出口需要更长的时间.
| 归档时间: |
|
| 查看次数: |
5770 次 |
| 最近记录: |