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?
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 .. –
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? –
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ó. –