Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone SDK: AVAudioRecorder will not record after calling [AVPlayer play]

I have a view controller that uses AVPlayer. this view controller can load a modal view controler where the user can record audio using AVAudioRecorder.

this is what happens:

if the user plays the composition in the fist controller with [AVPLayer play] the AVAudioRecorder will not record in the modal view controller. there are no errors but the current time returned by AVAudioRecorder is 0.0;

if the user dismisses the modal dialog and reloads it. AVAudioRecorder works fine.

this can be repeated over and over AVAudioRecorder does not work the first time it is invoked after a [AVPlayer play] call

I have been fighting with this for days and just have reorganized my code related to both AVPlayer and AVAudioRecorder and it's still acting weird.

Any help or pointer is much appreciated

Thanks in advance

Jean-Pierre

like image 957
Jean-Pierre Semery Avatar asked Mar 17 '11 21:03

Jean-Pierre Semery


2 Answers

I've been having the same problem too, and this is the solution I found.

When recording, write this line code after AVAudioRecord is initialized:

[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryRecord error:NULL];

Then invoke record method.

like image 154
Raynay Avatar answered Sep 21 '22 02:09

Raynay


How are you setting the AVAudioSession's category, i.e., play or record? Try something like

[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];
like image 34
Don Avatar answered Sep 20 '22 02:09

Don