AVAudioRecorder prepareToRecord works, but record fails

Posted by iPadDeveloper2011 on Stack Overflow See other posts from Stack Overflow or by iPadDeveloper2011
Published on 2011-02-01T11:18:36Z Indexed on 2011/03/07 0:10 UTC
Read the original article Hit count: 298

Filed under:

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?

© Stack Overflow or respective owner

Related posts about avaudiorecorder