MicrosoftEdge / WebView2Feedback

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

How to set default camera in webview2? #789

Open MinChanSike opened 3 years ago

MinChanSike commented 3 years ago

When a PC has multiple cameras, how to set default camera and disable for Ask before accessing camera like Edge/Chrome browser? image

Version SDK: 1.0.721-prerelease Runtime: 87.0.664.66 (64-bit) Framework: WPF OS: Win10

Sample html code to play the webcam video after page is loaded.

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>SampleWebCam</title>
    <style>
        .vContainer {
            margin: 0px auto;
            width: 500px;
            height: 375px;
            border: 10px #333 solid;
        }
        #videoElement {
            width: 500px;
            height: 375px;
            background-color: #666;
        }
    </style>
</head>

<body>
    <div class="vContainer">
        <video id="videoElement" autoplay />
    </div>
    <script>
        const video = document.querySelector("#videoElement");
        if (navigator.mediaDevices.getUserMedia) {
            navigator.mediaDevices.getUserMedia({ video: true })
                .then(function (stream) {
                    video.srcObject = stream;
                })
                .catch(function (err0r) {
                    console.log("Something went wrong!");
                });
        }
    </script>
</body>
</html>

AB#39500192

champnic commented 3 years ago

For the "Ask before accessing camera" issue, you can see if the PermissionRequested event catches it (I'm not sure if it does or not), and then it won't display UI: https://docs.microsoft.com/en-us/dotnet/api/microsoft.web.webview2.core.corewebview2.permissionrequested?view=WebView2-dotnet-1.0.664.37

For setting a default camera, we don't currently have a way to do this, so I've added an item on our backlog. Thanks!

champnic commented 3 years ago

Looks like there may be HTML/JS ways to choose the camera: https://stackoverflow.com/questions/21196473/how-to-select-camera-in-webapp https://webrtc.github.io/samples/src/content/devices/input-output/

Want to give those a try?

MinChanSike commented 3 years ago

Thanks, it work for me to allow "Ask before accessing camera" by PermissionRequested event handler. To choose camera by javascript, I also tried but navigator.mediaDevices.enumerateDevices() is not fully support without HTTPS, not convenience for development. Sometime if you are using third party application, it's need to set default camera for that application.

dcreurer commented 2 years ago

We are running MS Teams meetings within the WebView2 control in our app and would also like to be able to set the default camera, microphone and speaker. In our case we have a capture card showing up in the camera list and sometimes it is the selected camera.