Using AVAudioRecorder and AVAudioPlayer at the same time (or alternative ways of listening for sound and playing sound)

StackOverflow https://stackoverflow.com/questions/4255717

Question

Is there any reason why this wouldn't work?

I'm testing for sound in the microphone and playing a looping sound effect as I'm registering sound.

On the iPod touch this seems to work fine - on the iPhone though the sound effect either doesn't play at all, or is very quiet.

Any ideas? Or any alternative?

Thanks

Was it helpful?

Solution

for some reason had to put this code before I played the sound:

UInt32 sessionCategory = kAudioSessionCategory_MediaPlayback;
        AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(sessionCategory), &sessionCategory);    
        UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
        AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute,sizeof (audioRouteOverride),&audioRouteOverride);

to stop it playing through the earpiece.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top