androidkotlinvideowebviewandroid-automotive

How can I set WebView video volume to 0 in Android Automotive OS?


I am playing a video in the WebView. In normal emulators, I can set the volume to 0 by dragging the volume indicator to the minimum.

audioManager.getStreamVolume(AudioManager.STREAM_MUSIC)
// It returns 0 on phone or tablet emulators

However, when I attempt to set the volume to 0 in the Android Automotive OS emulator, even if I drag the volume bar indicator to the minimum, it remains at 15 instead of 0, and the video audio continues to play.

audioManager.getStreamVolume(AudioManager.STREAM_MUSIC)
// It returns 15 in the automotive emulator

I tried to set it to 0 programmatically, but it didn't work.

audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, 0, 0)

Solution

  • Android Automotive OS devices are very often "fixed-volume" devices meaning the volume cannot be controlled programmatically using that API (and others). The generic Android Automotive OS images are fixed-volume.

    Since you're using a WebView, I'm not sure that any of the options described in Working with fixed-volume devices are applicable, but perhaps you could change the stream volume of the video player web element? e.g. https://stackoverflow.com/a/21859511/17997552