Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AVAssetExportSession exportAsynchronouslyWithCompletionHandler: method Not Called

I'm combining two audio recordings (recorded using AVAudioRecorder) into one file. Using AVAssetExportSession to export the combined file works perfectly the first time (i.e. as long as I'm in the current view controller) But when load this view again (a new session) the AVAssetExportSession exportAsynchronouslyWithCompletionHandler: method does not get called at all (no call back!) No errors no nothing... I tried to log the AVAssetExportSession object, i get this the first time

<AVAssetExportSession: 0x155b3250, asset = <AVMutableComposition: 0x156474c0 tracks = ("<AVMutableCompositionTrack: 0x156a0bb0 trackID = 1, mediaType = soun, editCount = 0>")>, presetName = AVAssetExportPresetAppleM4A, outputFileType = (null)

and this the second time

<AVAssetExportSession: 0x1559e840, asset = <AVMutableComposition: 0x155f7f30 tracks = ("<AVMutableCompositionTrack: 0x155f0120 trackID = 1, mediaType = soun, editCount = 1>")>, presetName = AVAssetExportPresetAppleM4A, outputFileType = (null)

The only difference I noticed is the editCount = 1 thing.

I know it sounds confusing, it is to me. whatever is going on here?

My code:

AVAssetExportSession* exportSession = [AVAssetExportSession
                                       exportSessionWithAsset:composition
                                       presetName:AVAssetExportPresetAppleM4A];

NSLog(@"exportSession: %@", exportSession);


exportSession.outputURL = [NSURL fileURLWithPath:combined];
exportSession.outputFileType = AVFileTypeAppleM4A;
exportSession.shouldOptimizeForNetworkUse = YES;
[exportSession exportAsynchronouslyWithCompletionHandler:^{
    switch (exportSession.status) {
        case AVAssetExportSessionStatusFailed:
            NSLog(@"AVAssetExportSessionStatusFailed");
            break;
        case AVAssetExportSessionStatusCompleted:
            NSLog(@"AVAssetExportSessionStatusCompleted");
            break;
        case AVAssetExportSessionStatusWaiting:
            NSLog(@"AVAssetExportSessionStatusWaiting");
            break;
        default:
            break;
    }

    dispatch_async(dispatch_get_main_queue(), ^{
        [self exportDidFinish:exportSession];
    });

}];
like image 910
Ed Liss Avatar asked Oct 21 '22 14:10

Ed Liss


1 Answers

It may or may not be related, but I have had a similar issue with videos. The completion block won't fire if the export session doesn't have correct information about the AVAsset start time and duration. The only workaround I found was to seek in a small amount of time for each asset when adding them to the composition track (CMTimeRangeMake()). It's not ideal.

like image 131
Shocks Avatar answered Nov 15 '22 03:11

Shocks