You can use the AVAudioSessionCategoryOptionMixWithOthers
.
For instance,
AVAudioSession *session = [AVAudioSession sharedInstance];
[session setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionMixWithOthers error:nil];
After that, you can use the AVAudioPlayer
simultaneously with AVCaptureSession
.
However, the above code leads to very low volume.
If you want normal volume, use the AVAudioSessionCategoryOptionDefaultToSpeaker
with AVAudioSessionCategoryOptionMixWithOthers
as follows,
[session setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionMixWithOthers|AVAudioSessionCategoryOptionDefaultToSpeaker error:nil];
This goes well.