2011-09-07 34 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); 
     } 
    } 
} 
相關問題