2011-09-07 38 views
10

Im使用AVAssetExportSession转换*.caf文件,它在4.0模拟器和我的iPhone 4测试设备上运行得非常好。AVSsetExportSession在iPhone 3G上失败 - 但不在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}

可能是什么原因呢?

回答

0

最有可能的3G设备缺乏硬件编解码器来做相关的转换。你可以在3G上播放caf文件来测试它是否可以对其进行解码,并且您是否尝试过转换简单的wav来证明它可以进行编码?

+0

我可以在设备上播放caf文件。使用'exportPresetsCompatibleWithAsset'我发现在iPhone 3G上只有'AVAssetExportPresetAppleM4A'编解码器可用 - 所以我的设置应该很好.. –

+0

你能写一个文件到'self.tempDir',并且有足够的空间用于预期的大小的文件? –

+0

是的,我在转换之前使用AVAudioRecorder将文件记录到self.tempDir。 –

43

,你要保存文件

所以,你应该删除该文件的路径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); 
     } 
    } 
} 
相关问题