开发者

AVAssetExportSession fails on iPhone 3G - but not on iPhone 4

开发者 https://www.devze.com 2023-04-03 18:37 出处:网络
Im converting a *.caf file using AVAssetExportSession it works pretty well on the 4.0 Simulator and on my iPhone 4 testdevice.

Im converting a *.caf file using AVAssetExportSession it works pretty well on the 4.0 Simulator and on my iPhone 4 testdevice.

Sadly it always fails on an iPhone 3G with following function:

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 ev开发者_如何学Goent 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);

    }

}];

The following error is thrown every time.

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

What could be the reason for this?


11823 error comes when file already exist on the path where you are trying to save the file

So you should remove the file.

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


Most likely the 3G device lacks the hardware codecs to do the relevant transform. Can you play the caf file on the 3G to test it can decode it, and have you tried converting something simple like a wav to prove it can do encode?

0

精彩评论

暂无评论...
验证码 换一张
取 消