MicrosoftEdge / WebView2Feedback

Feedback and discussions about Microsoft Edge WebView2
https://aka.ms/webview2
449 stars 53 forks source link

Get and set audio volume #41

Open verelpode opened 5 years ago

verelpode commented 5 years ago

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:

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 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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

verelpode commented 5 years ago

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 commented 4 years ago

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 commented 4 years ago

@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 commented 4 years ago

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

DjSt3rios commented 4 years ago

I agree that this feature would be very useful.

liminzhu commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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: https://github.com/MicrosoftEdge/WebView2Feedback/pull/1658. Please review and add any feedback you have about this API.

dianaqu commented 3 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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.