html - 可以访问网络摄像头,无法显示视频
问题描述
实现代码时网络摄像头绿灯亮,但是摄像头窗口没有出来,而是一直出现“无法访问摄像头。错误: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;
});
}
解决方案
推荐阅读
- sql - 如何创建动态 sql 查询来更新表列
- php - 如何通过ajax请求在froala编辑器中发送额外的表单数据?
- python - Django Model Mocking - 更好地创建模型或模拟模型进行测试?
- android - 将约束布局库升级到 2.0.2 应用程序崩溃后
- r - 在 r 中读取和重塑数据框
- optimization - 在 Z3 中优化有符号位向量
- typescript - 根据返回类型限制 keyof 'Type'
- arrays - Ruby 为哈希数组在哈希内设置哈希
- git - 如何仅向 bitbucket 中的 bitbucket-pipelines 用户授予写入权限
- windows - 存储和检索存储在 HKLM 中的注册表项的问题