Note that there are some explanatory texts on larger screens.

plurals
  1. POAVAudioRecorder won't record IF movie was previously recorded & played
    text
    copied!<p>My iPhone app uses "AVAudioRecorder" to make voice recordings. It also uses "UIImagePickerController" to record movies and "MPMoviePlayerController" to play movies. </p> <p>Everything works fine until I do all three things in a row:</p> <ol> <li>Record a movie using UIImagePickerController</li> <li>Play back the recorded movie using MPMoviePlayerController</li> <li>Try to make a voice recording using AVAudioRecorder</li> </ol> <p>When I call AVAudioRecorder's "record" method in step 3, it returns NO indicating failure, but giving no hints as to why (come on Apple!) AVAudioRecorder's audioRecorderEncodeErrorDidOccur delegate method is never called and I receive no other errors when setting up the recorder.</p> <p>My first guess was that the movie recording/playing was modifying the shared instance of "AVAudioSession" in such a way that it prevented the audio recorder from working. However, I'm manually setting AVAudioSession's category property to "AVAudioSessionCategoryRecord" and I make the audio session active before trying to record.</p> <p>Here's my method for creating the recorder:</p> <pre><code>- (void)createAudioRecorder { NSError *error = nil; AVAudioSession *audioSession = [AVAudioSession sharedInstance]; [audioSession setCategory:AVAudioSessionCategoryRecord error:&amp;error]; if (error) ... [audioSession setActive:YES error:&amp;error]; if (error) ... NSMutableDictionary *settings = [[NSMutableDictionary alloc] init]; // General Audio Format Settings [settings setValue:[NSNumber numberWithInt:kAudioFormatMPEG4AAC] forKey:AVFormatIDKey]; [settings setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey]; [settings setValue:[NSNumber numberWithInt:1] forKey:AVNumberOfChannelsKey]; // Encoder Settings [settings setValue:[NSNumber numberWithInt:AVAudioQualityMin] forKey:AVEncoderAudioQualityKey]; [settings setValue:[NSNumber numberWithInt:96] forKey:AVEncoderBitRateKey]; [settings setValue:[NSNumber numberWithInt:16] forKey:AVEncoderBitDepthHintKey]; // Write the audio to a temporary file NSURL *tempURL = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:@"Recording.m4a"]]; audioRecorder = [[AVAudioRecorder alloc] initWithURL:tempURL settings:settings error:&amp;error]; if (error) ... audioRecorder.delegate = self; if ([audioRecorder prepareToRecord] == NO) NSLog(@"Recorder fails to prepare!"); [settings release]; } </code></pre> <p>And here's my method to start recording:</p> <pre><code>- (void)startRecording { if (!audioRecorder) [self createAudioRecorder]; NSError *error = nil; [[AVAudioSession sharedInstance] setActive:YES error:&amp;error]; if (error) ... BOOL recording = [audioRecorder record]; if (!recording) NSLog(@"Recording won't start!"); } </code></pre> <p>Has anyone run into this problem before?</p>
 

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