我有下一个在Chrome中运行良好的代码:
<!DOCTYPE html>
<a href="Default.html">Default.html</a>
<head>
<meta charset="utf-8"/>
<title></title>
<script type="text/javascript">
if (navigator.getUserMedia) {
navigator.getUserMedia(
// constraints
{
video: true,
audio: true
},
// successCallback
function (localMediaStream) {
var video = document.querySelector('video');
video.src = window.URL.createObjectURL(localMediaStream);
// do whatever you want with the video
video.play();
},
// errorCallback
function (err) {
console.log("The following error occured: " + err);
});
} else {
alert("getUserMedia not supported by your web browser or Operating system version");
}
</script>
</head>
<body>
<h2>Media Capture and Streaming</h2>
<p>Let's stream our video!</p>
<video autoplay></video>
</body>
</html>
但是我在使用Edge时遇到问题,因为在刷新每个页面时Edge都会询问新的“允许阻止麦克风请求”。是否可以像在Chrome中那样使其在Edge中永久存在?因为我知道可以在Chrome中永久使用此功能的网站,所以您不必每次都允许访问。
使用SSL(https)解决了该问题。