WKWebView ignores AVAudioSessionCategory

I tryed to play videos on WKWebView after the following codes.
1. Set AVAudioSessionCategory to SoloAmbient

do {
    try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategorySoloAmbient)
}
catch let error as NSError {
    print(error)
}

Error was not print.


2. Called setActive(true)

do {
    try AVAudioSession.sharedInstance().setActive(true)
}
catch let error as NSError {
    print(error)
}

Error was not print.


3. Checked current AVAudioSessionCategory

print("audioSession.category = \(AVAudioSession.sharedInstance().category)")

Output:

audioSession.category = AVAudioSessionCategorySoloAmbient


But, WKWebView ignores status of Ring/Silent switch, outputs video sound even if state of the switch is Silent.

I thought that this behavior is like AVAudioSessionCategoryPlayback.

UIWebView does not ignore.

Is there a solution?


I use devices below.

iPhone 5s : iOS 8.4.1

iPhone 6 plus : iOS 9.

Hello,


I am having the same problem. I am trying to set the audio mode to AVAudioSessionCategoryAmbient: 'Other apps should be able to play audio alognside yours. When the ringer switch is set to mute your audio is silenced, and when the screen locks, your audio stops'.


https://books.google.co.uk/books?id=ZgY_CQAAQBAJ&pg=PT186&dq=AVAudioSessionCategoryAmbient&hl=en&sa=X&ved=0ahUKEwjTldSW0tLKAhVHThQKHchaDjkQ6AEIIDAA#v=onepage&q=AVAudioSessionCategoryAmbient&f=false



This is the code I'm executing following this solution http://stackoverflow.com/questions/32673916/allow-users-background-music-in-swift-2-0

do
{ 
    try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryAmbient)
    try AVAudioSession.sharedInstance().setActive(true)
}
catch let error as NSError
{
    print(error)
}


WKWebView ignores the status of Ring/Silent switch. It is very important that my app does not play sound if the device is muted.

I would be very interested in a solution or a workaround.


I am currently testing it with an iPad4 MD510B/A however the same issue has been reported by some testers using iPhone 5c and iPhone 6.


Kind regards,

D. Pastor

Hi,

I'm having exactly the same issue as well, would love to get some help of how this problem can be solved

Hi,


I am having the same problem. Music apps stop playing music once a video ad is loaded in wkwebview.

Could someone solve this problem?


Thank you.

We are encountering the exact same issue. WKWebView does not respect the mute button and plays the video's audio.


None of the AVAudioSession settings have any effect and there does not appear to be any other way to mute the webview when the mute switch is on.


A radar ticket has been filed here: http://www.openradar.me/28716885.

WKWebView "ignores" the app sharedInstance AVAudioSessionCategory because it doesn't use it. It has its own AVAudioSessionCategory not available directly (as it runs in a separate process). This latter AVAudioSessionCategory can be indirectly influenced by <audio> and <video> html5 elements or their javascript counterparts. When audio starts playing through either of them the category switches from Ambient to Playback, and snaps back when it stops. To achieve the behavior of respecting the hardware silent switch one must not use audio and video html elements (or js equivalents).

We need WKWebView to use the ear piece as the audio device. Since it ignores AVAudioSessionCategory this is also not possible. If WKWebView has its own AVAudioSession it should be made accessible, how/where can we ask for that to happen ?

WKWebView ignores AVAudioSessionCategory
 
 
Q