Setting AVAudioSession Category has no effect on sound from WKWebView

倖福魔咒の 提交于 2019-12-03 13:55:42

So apparently WKWebView runs in a separate process from your app. Which probably means, it has its own AudioSession separate from your app's AudioSession as well. That's why changes to your app's AudioSession won't affect the webView. And also why it works with UIWebView (no separate process). At least that's what I gathered so far...

The solution for me was to allow my app's AudioSession to mix with others:

[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord 
                                 withOptions:AVAudioSessionCategoryOptionMixWithOthers
                                       error:&error];

Of course this has other implications as well. Your app's audio will be mixed with all other apps' audio, not just your webview's.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!