WKWebView audio volume control

Using WKWebView in iOS, I encountered a problem with controlling audio output level from <audio> element in HTML page.

I tried the 'volume' property of the <audio> and also the Web Audio API 'GainNode'. Neither approach worked.

The player's output stays/reported as 1.0.

Curiously, within the same scope of code I can change player's other properties such as playback rate; this does work. But calls to 'volume' or 'GainNode' are flatly ignored.

Two observations make me believe that this is a bug.

The first one: if I use instead of WKWebView the old deprecated UIWebView, everything works fine; even Web Audio API AudioContext, Splitter, Merger, etc.

The second observation: in the version of the app for macOS the very same HTML page and <audio> element behave as expected.


Any suggestions for 'workaround' would be much appreciated,

Igor Borodin

As you said the volume control of the HTML element doesn't affect on IOS device.

If you look on YouTube for example you will see that the volume control doesn't appear to the user.

In addition, if you try to open on IOS Safari the YouTube in dektop view you will see that the volume control has no effect.


The volume on IOS can be changed by the user on the hard volume buttons


OR


Programmatic:

let volume = 1

(MPVolumeView().subviews.filter{NSStringFromClass($0.classForCoder) == "MPVolumeSlider"}.first as? UISlider)?.setValue(volume, animated: false)

In mobile safari in JavaScript you can set the volume of audio just fine myAudio.volume = 0.5; myAudio.play(); But the same code inside a WKWebView does not work. myAudio.volume is still 1 after setting it to 0.5. This is a bug in WKWebView that has existed for over a year now. I want a solution.

WKWebView audio volume control
 
 
Q