AVAssetExportSession在iPhone 3G上失败 - 但在iPhone 4上没有

时间:2011-09-07 11:58:07

标签: iphone ios audio

我使用*.caf转换AVAssetExportSession文件,它在4.0模拟器和我的iPhone 4测试设备上运行良好。

可悲的是,在具有以下功能的iPhone 3G上总是失败:

AVAssetExportSession *exportSession = [AVAssetExportSession exportSessionWithAsset:avAsset presetName:AVAssetExportPresetAppleM4A];

 if (exportSession == nil) {

      NSLog(@"no export session");

      return NO;

 }

 exportSession.outputURL = [NSURL fileURLWithPath:self.tempDir];

 exportSession.outputFileType = AVFileTypeAppleM4A;


 [exportSession exportAsynchronouslyWithCompletionHandler:^{



    if (AVAssetExportSessionStatusCompleted == exportSession.status) {

        NSLog(@"AVAssetExportSessionStatusCompleted");


 } else if (AVAssetExportSessionStatusFailed == exportSession.status) {

        // a failure may happen because of an event out of your control

        // for example, an interruption like a phone call comming in

        // make sure and handle this case appropriately

        NSLog(@"AVAssetExportSessionStatusFailed");

     NSLog(@"%@", [exportSession.error description]);

    } else {

        NSLog(@"Export Session Status: %d", exportSession.status);

    }

}];

每次都会抛出以下错误。

Error Domain=AVFoundationErrorDomain Code=-11823 "Cannot Save" UserInfo=0x16fb20 {NSLocalizedRecoverySuggestion=Try saving again., NSLocalizedDescription=Cannot Save}

这可能是什么原因?

2 个答案:

答案 0 :(得分:47)

11823 error comes when file already exist在您尝试保存文件的路径上

所以你应该删除该文件。

- (void) removeFile:(NSURL *)fileURL
{
    NSString *filePath = [fileURL path];
    NSFileManager *fileManager = [NSFileManager defaultManager];
    if ([fileManager fileExistsAtPath:filePath]) {
        NSError *error;
        if ([fileManager removeItemAtPath:filePath error:&error] == NO) {
            NSLog(@"removeItemAtPath %@ error:%@", filePath, error);
        }
    }
}

答案 1 :(得分:0)

很可能3G设备缺少硬件编解码器来进行相关转换。你可以在3G上播放caf文件测试它可以解码吗,你试过转换像wav一样简单的东西来证明它可以编码吗?