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];
});
}];
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With