Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AVAudioRecorder hasn't sound

i have a problem with AVAudioPlayer in Some Condition. in first my audio recorder working Fine generally. but after VOIP call and play ring from built_in_Speaker and work many with audio session , after hangup the call ,i can't record Audio with sound in first! but in second time every thing working fine. Problem

in condition that i have mentioned my audio was record but hasn't voice!

i want to know in which situation maybe it happen?

 self.audioSession = [AVAudioSession sharedInstance];
NSError *err = nil;
[self.audioSession setCategory :AVAudioSessionCategoryPlayAndRecord error:&err];
if(err){
    NSLog(@"audioSession: %@ %d %@", [err domain], [err code], [[err userInfo] description]);
    return;
}

BOOL preparedToRecord = [self.audioRecorder prepareToRecord];
__block BOOL recordStarted = NO;

err = nil;
[self.audioSession setActive:YES error:&err];
if(err){
    NSLog(@"audioSession: %@ %d %@", [err domain], [err code], [[err userInfo] description]);
    return;
}

if (preparedToRecord){
    recordStarted = [self.audioRecorder record];
}
like image 906
Mo Farhand Avatar asked Feb 01 '16 08:02

Mo Farhand


Video Answer


1 Answers

Solved

i have found the reason of this problem. i have addObserve my self to catch the notification of AVAudioSession, and check the AudioSession interrupt/RoutChanging! the problem is after my call i have try to change audio route to speaker but a class that addobserved for AudioRoutChanging notification try to prevent that. so the audio session route change every second and couldn't record the audio.

Conclusion you should do like this for recording the audio:

1) sure about permission

2)[self.audioSession setActive:YES error:&err];

3)[self.audioSession setCategory :AVAudioSessionCategoryPlayAndRecord error:&err];

4) sure about your route don't be change during recording.

4)sure about your destination patch

like image 118
Mo Farhand Avatar answered Oct 15 '22 00:10

Mo Farhand