I just built and tested a basic AVAudioRecorder/AVAudioPlayer sound recorder and player. Eventually I got this working on the device, as well as the simulator. My player/recorder code is in a single UIView subclass. Unfortunately, when I copy the class into my main project, it no longer works (on the device--the simulator is fine). prepareToRecord is working fine, but record isn't. Here is some code:

I've found the problem. Elsewhere in my main project I use a Cocos2d "SimpleAudioEngine", which has its own [AVAudioSession sharedInstance]. My guess is that this somehow interferes with my audio session settings, for instance, this: [audioSession setCategory :AVAudioSessionCategoryPlayAndRecord error:&error]; Anyhow, when I remove my SimpleAudioEngine, my recorder/player works. Of course that leaves me with another problem...
–
iPadDeveloper2011Feb 1 '11 at 21:15

1 Answer
1

The complete solution was to move the [SimpleAudioEngine sharedEngine] initialisation to before my own AVAudioSession setCategory. I think somewhere in SimpleAudioEngine, its doing a setCategory :AVAudioSessionCategoryAmbient. Overriding this with my own setCategory :AVAudioSessionCategoryPlayAndRecord later makes everything work.