1
votes

Ok. I think I'm missing something here and I'm new to Core Audio but I have scoured the Apple documents and the rest of the web to no avail. I've also posted this same question to the apple dev forums and got no replies. I'm hoping the StackOverflow community can help me out.

I'm recording audio and playing it back just fine using AVAudioRecorder and AVAudioPlayer. My app also uses file sharing so the user can export the audio and play it elsewhere. This is where my issue comes in. I'm recording using AAC encoding but the file will not import into iTunes. It plays fine using VLC and looking at the media information its' codec is mp4a which I expected.

Reading on the web its sounding like the AAC needs a mp4a wrapper. Can anyone enlighten me or direct me to some info on this? Possibly an API or 3rd party library I can use?

I've played with the SpeakHere and ExtAudioFileConvertTest examples, added file sharing, recorded as AAC but they still won't play in iTunes.

Here's my recording code. Very grateful for any suggestions or guidance. Thanks!

 NSDictionary *recordSettings = [[NSDictionary alloc] initWithObjectsAndKeys:
      [NSNumber numberWithFloat: 44100.0], AVSampleRateKey,
      [NSNumber numberWithInt: kAudioFormatMPEG4AAC], AVFormatIDKey,
      [NSNumber numberWithInt: 1], AVNumberOfChannelsKey,
      [NSNumber numberWithInt: AVAudioQualityMax],AVEncoderAudioQualityKey,
      nil];

     ...     


NSError *error;
recorder = [[AVAudioRecorder alloc] initWithURL: soundFileURL
                               settings: recordSettings
                                error: &error];
1

1 Answers

2
votes

Figured this out with some help from some on the Apple forums. All I had to do was set the filename extension to m4a! Changing the extension manually and trying to play in iTunes does not work. Something under the covers in AVAudioRecorder seems to use the extension to encode the file correctly. Just set the extension correctly and it works beautifully. Hope this helps someone else out in the future.