Skip to content

Get and set audio volume #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
verelpode opened this issue Aug 20, 2019 · 21 comments
Open

Get and set audio volume #41

verelpode opened this issue Aug 20, 2019 · 21 comments
Assignees
Labels
feature request feature request priority-low We have considered this issue and decided that we will not be able to address it in the near future. tracked We are tracking this work internally.

Comments

@verelpode
Copy link

verelpode commented Aug 20, 2019

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

@david-risney david-risney added the feature request feature request label Sep 12, 2019
@david-risney
Copy link
Contributor

Good suggestion. We should also consider this in light of things like the Media Transport Controls for UWP apps. Volume but also play, pause, media information etc.

@verelpode
Copy link
Author

Re Media Transport Controls -- although in general I like the idea of Play and Pause functions, I'm unsure how that would work when a webpage contains multiple video elements. I think the audio volume issue is simpler in the case of multiple video elements because the volume can simply apply to everything in the webpage. In contrast, if Play and Pause functions exist, and if they cause all video elements to start playing or pause, I'm unsure whether that's what people would want.

@david-risney
Copy link
Contributor

We'll look into the corresponding browser feature where the browser connects to MTC. What we do in this area will likely depend on that feature

@verelpode
Copy link
Author

verelpode commented Oct 1, 2019

Would those Media Transport Controls also make it possible to ask WebView2 whether it is currently playing any video? Our kiosks have a user inactivity/idle timeout. If no user activity is detected for longer than X minutes, the kiosk and web session is terminated/reset. However this causes a problem when users/employees are watching long training or OH&S videos. The user appears idle because he/she doesn't move the mouse or press any key while watching the long training video, and thus the inactivity timeout occurs and interrupts the playback of the training video. Thus we have a request from a client to (if possible) automatically detect when a video is playing in the WebView/2 and extend the inactivity timeout.

For example:

  1. Employee starts playing/watching a long training or OH&S video.
  2. No mouse movement or key presses occur for 10 minutes and the inactivity timeout is triggered.
  3. Ideally the inactivity timeout would then ask WebView2 whether any video is currently playing. If WebView2 says yes a video is playing (not paused or stopped or nonexistent), then extend the inactivity timeout by another 10 minutes, otherwise end/reset the kiosk and web session.

Detecting video playback and controlling the audio volume are 2 actual requests from real-life clients. Especially the audio volume has been requested multiple times.

@david-risney
Copy link
Contributor

Good point. Not sure if its required for MTC connection or not but a good feature request. Thanks.

@verelpode
Copy link
Author

Also relevant to volume control: Ideally the WebView2/Chromium process should not appear in the system sound mixer window. Alternatively, if it must appear, then it should appear with the name of the owning app. In contrast / for comparison, EdgeHTML-WebView appears like the following screenshot, which is confusing for end-users. Users don't (and shouldn't have to) understand what "Desktop App Web Viewer" means.

image

Even more confusing for users, when multiple apps or processes use WebView, then "Desktop App Web Viewer" appears multiple times in the volume mixer:

image

However, in our environment, being able to programmatically control the volume of WebView2 is much more important than whether or not it appears in the volume mixer window. And various other issues are much higher priority than audio issues, such as cookie access.

@vhanla
Copy link

vhanla commented Apr 22, 2020

Microsoft Edge WebView2 (developer preview) still has this volume mixer issue.
imagen
If I write a html5 video viewer with this WebView2 and another for audio playing, users won't know which is which, it will also fail to describe which application is sending a desktop notification if it is enabled on this new library.

@liminzhu
Copy link
Member

@vhanla thanks for posting it here :), we'll look into this

// fyi @david-risney we were talking about this on twitter https://twitter.com/vhanla/status/1252759195302100993

@douglas-jordan
Copy link

douglas-jordan commented Apr 23, 2020

Allowing the audio renderer to be changed or selected via API would be very useful as well.

@DjSt3rios
Copy link

I agree that this feature would be very useful.

@champnic champnic added feature request feature request and removed feature request feature request labels Aug 18, 2020
@liminzhu
Copy link
Member

liminzhu commented Jul 6, 2021

Hey folk. We are starting to look at an API to control the media audio. A clarifying question I want to ask - do you want control the volume of a particular media element, individual webview, all webviews you own, or the system volume? Thanks!

@douglas-jordan
Copy link

Hey folk. We are starting to look at an API to control the media audio. A clarifying question I want to ask - do you want control the volume of a particular media element, individual webview, all webviews you own, or the system volume? Thanks!

Selecting the audio renderer for each webview. This would allow control of volume and where it is output for every page, just like the way you can with video playback in DirectShow.

@dianaqu
Copy link
Contributor

dianaqu commented Aug 30, 2021

Hi folks on this thread. I am working on implementing the mute/unmute feature. There is a design question I have in mind that was hoping to get some insights from folks requesting the feature.

I am debating on whether to make the mute/unmute API async or not. What would be the user cases for the mute and mute API?

@verelpode

@douglas-jordan
Copy link

Hi folks on this thread. I am working on implementing the mute/unmute feature. There is a design question I have in mind that was hoping to get some insights from folks requesting the feature.

I am debating on whether to make the mute/unmute API async or not. What would be the user cases for the mute and mute API?

@verelpode

As previously stated, just allow us to specify the audio renderer and then we can do whatever we need, mute, volume up/down etc.

@dianaqu
Copy link
Contributor

dianaqu commented Aug 31, 2021

Hi folks on this thread. I am working on implementing the mute/unmute feature. There is a design question I have in mind that was hoping to get some insights from folks requesting the feature.
I am debating on whether to make the mute/unmute API async or not. What would be the user cases for the mute and mute API?
@verelpode

As previously stated, just allow us to specify the audio renderer and then we can do whatever we need, mute, volume up/down etc.

We wouldn't be able to provide volume change at this point. For the Mute/Unmute, do you need the setting mute finished before unmuting?

@dianaqu
Copy link
Contributor

dianaqu commented Sep 13, 2021

Hi folks on the thread,

We can't provide volume control at this moment, but we added ability to mute and unmute webview. Also ability to tell if webview is playing audio, so users can chose to time out or not. We have the spec here: #1658. Please review and add any feedback you have about this API.

@dianaqu
Copy link
Contributor

dianaqu commented Oct 14, 2021

Hi folks,

The API is now an experimental API now. Please give it a try if you would like.

https://www.nuget.org/packages/Microsoft.Web.WebView2/1.0.1018-prerelease

https://docs.microsoft.com/en-us/microsoft-edge/webview2/release-notes#101018-prerelease

@jarno9981
Copy link

jarno9981 commented Mar 13, 2022

Hi folks,

The API is now an experimental API now. Please give it a try if you would like.

https://www.nuget.org/packages/Microsoft.Web.WebView2/1.0.1018-prerelease

https://docs.microsoft.com/en-us/microsoft-edge/webview2/release-notes#101018-prerelease

@dianaqu

I try the api but still the same bahavior process shows as webview2 rather than the app name any idea
Latest pre-release package
Windows 11 latest beta build
Latest visual studio 2022

@Bahaa-Sobhy
Copy link

Is there any solution for the .NET versions yet?

Summary reminder:

  1. We need an event to detect whenever there's sound from a page.
  2. We need the name inside the Volume Mixer to be the name of our Application, or it would be better to give us a property or a method to name it, because we make Tabs manually inside TabControl, and we might need to label each sound in relation to its tab.

Thanks in advance.

@riverar
Copy link

riverar commented Mar 31, 2022

I'm the developer of EarTrumpet an alternative audio mixer and we are seeing an uptick in Edge/PWA/WebView2(?) users filing bugs on me because I can't control the volume of these apps due to mixed/brokered audio.

We need access to Core Audio API-like interfaces on a per-app/process basis. Happy to connect/discuss further.

@champnic champnic added the tracked We are tracking this work internally. label May 10, 2022
@github-actions github-actions bot added the priority-low We have considered this issue and decided that we will not be able to address it in the near future. label Mar 26, 2024
@cryptofyre
Copy link

Bump, this is sorta irritating having absolutely no way of controlling these subprocesses in userland programmatically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request feature request priority-low We have considered this issue and decided that we will not be able to address it in the near future. tracked We are tracking this work internally.
Projects
None yet
Development

No branches or pull requests