AVAudioSession configuration to record and play sound with others

I want to configure AVAudioSession that I can record video with audio and also play music from Music app (or any other app that is producing sound, typically internet radios apps)

I configure session like this:


try? AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayAndRecord, with: .mixWithOthers)

try? AVAudioSession.sharedInstance().setActive(true, with: .notifyOthersOnDeactivation)

This works the way that when my recording app is running I can start playing audio from music app and record video (also record audio as well). So far good.

Now, I put my recording app to the background. Music app continues to play. It is fine. But, when my app is coming back from background music app stop its playback. I would like it to continue. So it basically behaves as build in camera app when shooting video. Is there a way to tell the system that I want other app to continue playback?

Support

According to the documentation, .notifyOthersOnDeactivation is meaningful only when the first parameter to setActive is 'false'. (You are using 'true'.)


It's not clear whether that has any effect on the behavior you see, but you could try a manual setActive(false, with: .notifyOthersOnDeactivation) when your app is going into the background, then setActive(true) when it comes back to the foreground (maybe after setting the category again).


Whether that helps or not, I suggest you submit a bug report about the behavior you're seeing. It does sound reasonable that the mixing should continue when your app comes out of the background. (But maybe there's a reason why it doesn't.)

If you're still seeing this issue, could you submit a bug report and post the bug number here? The behavior you're describing doesn't sound like something that's supposed to happen, but it's going to take a bug report to bring it to the attention of the people who can investigate.

AVAudioSession configuration to record and play sound with others
 
 
Q