Skip to content

Get and set audio volume #41

@verelpode

Description

@verelpode

Every so often, we receive yet another request for a feature that controls the audio volume of the web component. So far, we have been unable to fulfill this request. Can an AudioVolume property (equivalent to the following C# snippet) be added to WebView2?

class WebView2
{
    ...
    public double AudioVolume { get; set; }
    // Optional:   public bool IsAudioVolumeMuted { get; set; }
    ...
}

If you want, you could include the IsAudioVolumeMuted property to support a mute/unmute setting, but this isn't strictly essential, because apps can build their own mute/unmute setting atop the AudioVolume property. Note mute is different to setting the AudioVolume property to zero.

Valid values for the AudioVolume property would probably range from 0.0 (meaning 0%) to 1.0 (meaning 100%), but you might decide to also allow values greater than 100% because some volume controls do actually support "overdrive" or "boost" volumes, especially in cases where the source audio material may contain quiet sounds. Your choice.

I would find it helpful if the documentation states what scale the volume operates on:

  1. Logarithmic, or
  2. Linear.

Some audio volume slider widgets operate on a logarithmic scale while others are linear. A way of fixing a poorly performing volume slider is to change it to a logarithmic scale. However if the AudioVolume property is already logarithmic but the documentation doesn't state it, then an audio volume slider widget may be accidentally implemented as double log, which again produces a poorly behaving slider, thus clear documentation is helpful.

The proposed AudioVolume property would control the volume of all audio output produced by WebView2, including the following. Here is a list of tests to be performed after the volume feature is implemented:

  • Playback of video elements embedded in HTML webpages.
  • Playback of non-embedded video files (when WebView2 is directly navigated to a URI that directly returns a video file without HTML).
  • Audio elements such as playback of .WAV files.
  • Any audio produced via ECMAScript.
  • Fullscreen video elements.

I have not been able to workaround the lack of volume control by setting the system volume because:

  1. I couldn't work out how to correctly set the system volume. Windows (or the documentation) doesn't make it easy (or maybe it's easy but only if you know how).
  2. Even if I knew how to set the system volume, it's only partially helpful. It's not a full solution because we have alert/notifications sounds (outside of web) that should play at 100% volume while the web component should be 30% for example. Thus if the system volume is set to 30%, the alert sounds become so quiet that they're missed by people. Thus ideally WebView2's volume could be set independently.
  3. Even if the correct Win32 functions are known for setting the system volume, they're not necessarily allowed in the UWP sandbox.

AB#37633577

Metadata

Metadata

Assignees

Labels

feature requestfeature requestpriority-lowWe have considered this issue and decided that we will not be able to address it in the near future.trackedWe are tracking this work internally.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions