首页 > 解决方案 > 可以访问网络摄像头,无法显示视频

问题描述

实现代码时网络摄像头绿灯亮,但是摄像头窗口没有出来,而是一直出现“无法访问摄像头。错误: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;
    });
}

标签: htmldjango-templateswebcam

解决方案


推荐阅读