Faizan S.
Faizan S.

Reputation: 8644

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

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

    }

}];

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?

Upvotes: 12

Views: 6585

Answers (2)

shihongzhi
shihongzhi

Reputation: 1931

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

Upvotes: 48

Malcolm Box
Malcolm Box

Reputation: 4036

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?

Upvotes: 0

Related Questions