Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

ios

iphone

audio

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?

like image 613
Faizan S. Avatar asked Sep 07 '11 11:09

Faizan S.


1 Answers

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);
        }
    }
}
like image 126
shihongzhi Avatar answered Oct 18 '22 09:10

shihongzhi