2011-09-07 30 views
10

Im chuyển đổi tệp *.caf bằng cách sử dụng AVAssetExportSession nó hoạt động khá tốt trên Trình mô phỏng 4.0 và trên thử nghiệm iPhone 4 của tôi.AVAssetExportSession không thành công trên iPhone 3G - nhưng không phải trên iPhone 4

Đáng buồn thay nó luôn thất bại trên một chiếc iPhone 3G với chức năng sau:

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); 

    } 

}]; 

Các lỗi sau đây được ném mỗi lần.

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

gì có thể là lý do cho việc này?

Trả lời

0

Rất có thể thiết bị 3G thiếu codec phần cứng để thực hiện phép biến đổi có liên quan. Bạn có thể chơi các tập tin caf trên 3G để kiểm tra nó có thể giải mã nó, và có bạn đã cố gắng chuyển đổi một cái gì đó đơn giản như một wav để chứng minh nó có thể làm mã hóa?

+0

Tôi có thể phát tệp caf trên thiết bị. Sử dụng 'exportPresetsCompatibleWithAsset' Tôi phát hiện ra rằng chỉ có codec 'AVAssetExportPresetAppleM4A' có sẵn trên iPhone 3G - Vì vậy, cài đặt của tôi sẽ ổn thôi .. –

+0

Bạn có thể viết một tệp vào' self.tempDir' và có đủ không gian cho kích thước mong muốn không của tệp? –

+0

Có, tôi ghi tập tin đó vào self.tempDir bằng cách sử dụng AVAudioRecorder trước khi chuyển đổi nó. –

43

11823 error comes when file already exist trên con đường mà bạn đang cố gắng để lưu các tập tin

Vì vậy, bạn nên loại bỏ các tập tin.

- (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); 
     } 
    } 
} 
Các vấn đề liên quan