How to make getUserMedia() method works on Chromium Web browser inside WinForms application?

陌路散爱 提交于 2019-12-12 03:50:35

问题


I'm trying to get access to my webcam from my WinForms application using Chromium webbrowser control, to do that I installed my HTML file - which is shown below - to a server (on my machine) then I tried to navigate to it from my application but the error callback of getUserMedia() method was executed showing "Permission Denied Error", on the other hand it's working fine if I tried to navigate to it directly from chrome. So, is there anyone could know what causes this error ?

// client.js file

(function () {
    window.onerror = function (errorMsg, url, lineNumber) {
        alert(errorMsg, ',URL: ' + url + ' ,Line: ' + lineNumber);        
        return true;
    }
    })();

function hasUserMedia() {
    //check if the browser supports the WebRTC 
    return !!(navigator.getUserMedia || navigator.webkitGetUserMedia ||
       navigator.mozGetUserMedia);

}

if (hasUserMedia()) {
    navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia
       || navigator.mozGetUserMedia;
    
    //enabling video and audio channels 
    navigator.getUserMedia({ video: true, audio: true }, function (stream) {
        var video = document.querySelector('video');

        //inserting our stream to the video tag     
        video.src = window.URL.createObjectURL(stream);
    }, function (err) { alert(err.name + " : " + err.message  ); });
} else {
    alert("WebRTC is not supported");
}
<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title></title>
</head>
<body>
    <video autoplay></video>
    <script src="client.js"></script>
</body>
</html>

来源:https://stackoverflow.com/questions/38630903/how-to-make-getusermedia-method-works-on-chromium-web-browser-inside-winforms

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!