Exporting Audio FilesAKAudioFiles can be easily converted to major audio formats asynchronously.
Pick a file to convert :
Export will be done asynchronously. So you can play some music while exporting
You need a callback that will be triggered as soon as Export has been completed. the callback must be set as an AsyncProcessCallback with a signature set to be:
func callback(processedFile: AKAudioFile?, error: NSError?)
If export failed, "processedFile" will be nil. The error being thrown is given in the "error" parameter. If export succeeded, no error will be set (error = nil) and the exported file is returned as an AKAudioFile. The callback will print some information and replace the file being played with the exported file.
Next export the mixloop into a compressed .mp4 file :
Convert the file to .WAV format, and this time, set a range for the export
Each time an export has been completed and succeeded, the player will be set to play it.
Check the debug area. Notice that all file exports are done serially, in the order they were set.
Be aware that PCM format files can be converted to PCM or compressed formats. But compressed m4a or mp4 audiofiles cannot be converted to PCM files (.wav or .aif). For converting from any format compressed format to PCM, you can use AKAudioFile.extract or AKAudioFile.extractAsynchronously() methods (will convert to .CAF PCM). The resulting file can then be exported to .mp4, m4a, .wav, or .aif.