Problem using AVAudioRecorder.

Posted by tek3 on Stack Overflow See other posts from Stack Overflow or by tek3
Published on 2010-05-10T07:31:19Z Indexed on 2010/05/10 7:34 UTC
Read the original article Hit count: 520

Filed under:
|

Hi all,

I am facing a strange problem with AVAudioRecorder. In my application i need to record audio and play it. I am creating my player as :

if(recorder)
{
if(recorder.recording)
[recorder stop];
[recorder release];
recorder = nil;
}

NSString * filePath = [NSHomeDirectory() stringByAppendingPathComponent: [NSString stringWithFormat:@"Documents/%@.caf",songTitle]];
        NSDictionary *recordSettings = [[NSDictionary alloc] initWithObjectsAndKeys:
                                        [NSNumber numberWithFloat: 44100.0],AVSampleRateKey,
                                        [NSNumber numberWithInt: kAudioFormatAppleIMA4],AVFormatIDKey,
                                        [NSNumber numberWithInt: 1], AVNumberOfChannelsKey,
                                        [NSNumber numberWithInt: AVAudioQualityMax],AVEncoderAudioQualityKey,nil];
        recorder = [[AVAudioRecorder alloc] initWithURL: [NSURL fileURLWithPath:filePath] settings: recordSettings error: nil];
        recorder.delegate = self;
if ([recorder prepareToRecord] == YES){
                [recorder record];

I am releasing and creating player every time i press record button. But the problem is that ,AVAudiorecorder is taking some time before starting to record , and so if i press record button multiple times continuously ,my application freezes for some time. The same code works fine without any problem when headphones are connected to device...there is no delay in recording, and the app doesn't freeze even if i press record button multiple times. Any help in this regard will be highly appreciated.

Thanx in advance.

© Stack Overflow or respective owner

Related posts about iphone

Related posts about avaudiorecorder