Question

I've got a control in my app that records audio and saves it. I use AVMutableComposition to append new recordings to the old and when the user is ready to save, I'm trying to use AVAssetExportSession to write everything to a new file. When I do this I get no errors and a file is written. However, that file can't be played and my completion block never gets called. Does anyone have any idea what might be causing this?

Here's the code:

        AVAssetExportSession *exportSession = [AVAssetExportSession exportSessionWithAsset:composition presetName:AVAssetExportPresetAppleM4A];
        exportSession.outputURL = URL;
        exportSession.outputFileType = AVFileTypeAppleM4A;
        exportSession.shouldOptimizeForNetworkUse = YES;
        [exportSession exportAsynchronouslyWithCompletionHandler:^{
           NSLog(@"Export Complete");
        }];

The variable composition is an AVMutableComposition which has added to it one or more AVURLAssets (either previous or current recordings).

UPDATE

I don't know if this helps, but I'm using AVAudioRecorder to record the audio and I'm using the following settings:

[recordSetting setObject:[NSNumber numberWithInt:kAudioFormatMPEG4AAC] forKey:AVFormatIDKey];
[recordSetting setObject:[NSNumber numberWithFloat:44100.0] forKey: AVSampleRateKey];
[recordSetting setObject:[NSNumber numberWithInt:1] forKey:AVNumberOfChannelsKey];
[recordSetting setObject:[NSNumber numberWithInt:64000] forKey:AVEncoderBitRateKey];
[recordSetting setObject:[NSNumber numberWithInt: AVAudioQualityMedium] forKey: AVEncoderAudioQualityKey];

UPDATE 2

I've tried the same code using a AVURLAsset generated off of the recorded file, essentially cutting out the AVMutableComposition to make sure it's not the problem. It's still not working.

Any help on this would be greatly appreciated.

Was it helpful?

Solution

Alright, I figured it out. When I was recording audio, I was using a file extension .aac. However, when I exported the audio out I was using the file extension .m4a. I couldn't set the export file extension to .aac (the export failed), but when I set the recording extension to .m4a it all worked fine.

OTHER TIPS

You can use SDAVAssetExportSession to record to m4a with AAC encoder and then rename it AAC on complete.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top