I was googling this problem for many days but I didn\'t find a solution for my simple problem.
I\'m trying to play a video while recording sound. Recording sound wor
I had the same problem (except I'm using the AVPlayer to play audio and not video though). I suggest you start listening for audio routing changes and you will see the route change multiple times when the AVPlayer and AVAudioRecorder are started at the same time.
AudioSessionAddPropertyListener(kAudioSessionProperty_AudioRouteChange,
audioRouteChangeListenerCallback,
self);
In the callback print out the category and route (kAudioSessionProperty_AudioRoute). The only way I could get the audio playback and record to work simultaneously was if:
The audio session was AVAudioSessionCategoryPlayAndRecord and kAudioSessionProperty_OverrideCategoryMixWithOthers property was true.
I initiated the playback before the recording. After AVAudioRecorder prepareToRecord is called, don't start recording until you get the audio route change. Even though it does not fail if you start recording earlier, the audio route change seems to make the recording fail.
I tried other combinations, but this is the only one that works every time.