AVAudioRecorder prepareToRecord works, but record fails
- by iPadDeveloper2011
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:
audioRecorder = [[ AVAudioRecorder alloc] initWithURL:url settings:recordSettings error:&error];
if ([audioRecorder prepareToRecord]){
audioRecorder.meteringEnabled = YES;
if(![audioRecorder record])NSLog(@"recording failed!");
}else {
int errorCode = CFSwapInt32HostToBig ([error code]);
NSLog(@"preparedToRecord=NO Error: %@ [%4.4s])" , [error localizedDescription], (char*)&errorCode);
...
I get "recording failed". Anyone have any ideas why this is happening?