问题
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