javascript - 一切看起来都很好,但 getUserMedia 仍然无法正常工作
问题描述
一切看起来都很好。那么为什么我的代码不起作用?它甚至不请求许可。
这是我的代码。
var video = document.getElementById("video")
window.onload = () => {
if(navigator.mediaDevices){
navigator.mediaDevices.getUserMedia({
video: {
height: {
max: 2460,
ideal: 1690,
min:1080
},
width: {
max: 1940,
ideal: 1260,
min: 720
},
facingMode: 'user'
},
audio:false
})
.then(stream => {
video.srcObject = stream
}).catch(err){
document.write(err.message + "\nPlease allow camera access to use this site...")
}
}
else{
alert("Your device doesn't support this feature")
document.write("Your browser doesn't support this feature")
}
}
我也使用过和不使用这个:
var mediaDevices = mediaDevices || webkitMediaDevices || mozMediaDevices
和这个:
var mediaDevices = navigator.mediaDevices || navigator.webkitMediaDevices || navigator.mozMediaDevices
仍然无法正常工作
解决方案
推荐阅读
- sql - SQL 根据条件汇总
- java - spring 中的单例可以有静态方法吗?
- android - 如何使用 Dagger 在 Retrofit2 android 中动态传递不同的 url
- eclipse - 比尔特 4.7。预览不适用于 Eclipse IDE
- c# - 如何在 WPF 中对 GridViewColumns 进行分组,以便扩展器填充整个宽度
- python - Django 2 中的 MultiSelect 字段不起作用
- python - Python kivy 找不到任何有价值的窗口提供程序
- c - atof("0") 在浮点变量中返回 2
- excel - 我怎样才能把这个数据集转换成这个特定的顺序?
- docker - 如何使用 dockerode 推送图像?(图像未推送但没有错误)