当我实现代码时,网络摄像头绿灯亮,但是凸轮窗口没有熄灭,相反,“无法访问照相机。错误:TypeError”不断出现……是否存在我的代码中有任何错误吗?
if (navigator.mediaDevices) {
// access the web cam
const constraints = {video:true, audio:false}
navigator.mediaDevices.getUserMedia(constraints)
// permission granted:
.then(function(stream) {
video.src = window.URL.createObjectURL(stream);
video.addEventListener('click', takeSnapshot);
})
// permission denied:
.catch(function(error) {
document.body.textContent = 'Could not access the camera. Error: ' + error.name;
});
}