Why is AVAudioSession setCategory is not working in WKWebView?

I am developing a WebRTC based iOS application. As part of my application, I also play a YouTube video through using https://developers.google.com/youtube/v3/guides/ios_youtube_helper. I use the following code to mix the audio;



NSError *error = nil;

[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord

withOptions: AVAudioSessionCategoryOptionMixWithOthers | AVAudioSessionCategoryOptionDefaultToSpeaker

error: &error];

if (error != nil) {

NSLog(@"Problem setting up AVAudioSession to mix with others");

}


The problem is when WebRTC chat is on, YouTube video volume is extremely low. If I disconnect WebRTC chat, YouTume video volume becomes normal. Neither WebRTC nor YouTube player is setting AVAudioSessionCategoryOptionDuckOthers or chaging AudioSession category.

Is there any problem in WKWebView working shared AVAudioSession?

Thanks,

Over 3 years later and no action on this. Really pathetic.

Really pathetic.
You might want to check this. https://stackoverflow.com/a/62840934/772481

The answer appears to be that the AVAudioSession.Mode is automatically setting some options under the hood. Apple seems to have made the design decision that the .voiceChat mode should always duck others for the best experience. This is similarly true in the .videoChat mode, both of which are the obvious modes to use with an Agora call. Using those modes seems to automatically set the .duckOthers flag.
I was able to solve this issue by setting the mode to .videoRecording, which is designed for apps that are recording audio and video, and therefore doesn't automatically set .duckOthers. Because this isn't actually what you're doing, it's definitely a workaround, and might have other side effects.
Why is AVAudioSession setCategory is not working in WKWebView?
 
 
Q