Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy is AVAudioRecorder prepareToRecord Failing?
    text
    copied!<p>I am trying to setup a basic controller that will record user audio input(voice). However, the AVAudioRecorder's prepareToRecord method is failing and I can't figure out why. I have setup the audio session in my app delegate and I do not receive an errors when I instantiate the AVAudioRecorder instance:</p> <p>// App delegate snippet</p> <pre><code>AVAudioSession* audioSession = [AVAudioSession sharedInstance]; NSError* audioSessionError = nil; [audioSession setCategory: AVAudioSessionCategoryPlayAndRecord error: &amp;audioSessionError]; if (audioSessionError) { NSLog (@"Error setting audio category: %@", [audioSessionError localizedDescription]); } else { NSLog(@"No session errors for setting category"); } [audioSession setActive:YES error:&amp;audioSessionError]; if (audioSessionError) { NSLog (@"Error activating audio session: %@", [audioSessionError localizedDescription]); } else { NSLog(@"no session errors for setActive"); } </code></pre> <p>// VIEW DID LOAD IN RECORDERCONTROLLER</p> <pre><code>- (void)viewDidLoad { self.navigationItem.title = [NSString stringWithFormat:@"%@", [[MyAppDelegate loadApplicationPlist] valueForKey:@"recorderViewTitle"]]; self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(dismiss)]; [self alertIfNoAudioInput]; [self createAVAudioRecorder]; minutesSecondsFormatter = [[SimpleMinutesSecondsFormatter alloc] init]; currentTimeUpdateTimer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(updateAudioDisplay) userInfo:NULL repeats:YES]; [super viewDidLoad]; } </code></pre> <p>// CREATE AVAUDIORECORDER</p> <pre><code>- (NSError *)createAVAudioRecorder { NSError *recorderSetupError = nil; [audioRecorder release]; audioRecorder = nil; NSString *timestamp = [NSString stringWithFormat:@"%d", (long)[[NSDate date] timeIntervalSince1970]]; NSString *destinationString = [[MyAppDelegate getAppDocumentsDirectory] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.caf", timestamp]]; NSLog(@"destinationString: %@", destinationString); NSURL *destinationUrl = [NSURL fileURLWithPath: destinationString]; audioRecorder = [[AVAudioRecorder alloc] initWithURL:destinationUrl settings:[[AVRecordSettings sharedInstance] getSettings] error:&amp;recorderSetupError]; if (recorderSetupError) { UIAlertView *cantRecordAlert = [[UIAlertView alloc] initWithTitle:@"Can't record" message:[recorderSetupError localizedDescription] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [cantRecordAlert show]; [cantRecordAlert release]; return recorderSetupError; } else { NSLog(@"no av setup error"); } if ([audioRecorder prepareToRecord]) { recordPauseButton.enabled = YES; audioRecorder.delegate = self; } else { NSLog(@"couldn't prepare to record"); } NSLog (@"recorderSetupError: %@", recorderSetupError); return recorderSetupError; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload