navigator.mediaDevices.enumerateDevices()返回空标签 [英] navigator.mediaDevices.enumerateDevices() returns empty labels
问题描述
背景
我尝试在其上实现的机器包含多台摄像机,我想在代码中选择摄像机.(所有机器都具有相同的硬件)
The machine I am trying to implement this on contains multiple cameras, I want to select the camera in the code. (all machines have the same hardware)
问题
我正在尝试实现自定义功能,然后再请求访问视频,在该视频中,我手动设置了应使用的设备,以防止选择错误的摄像机,但是在使用时
I am trying to implement a custom function before requesting video access where I manually set which device that should be used to prevent selection of wrong camera, but when I use
等待navigator.mediaDevices.enumerateDevices()
我为可用的摄像机设备得到了空标签.
I get empty labels for available video camera devices.
推荐答案
navigator.mediaDevices.enumerateDevices()如果未提供访问mediadevice的权限,将返回一个空的标签属性值.尝试在getUserMedia之后使用它.
navigator.mediaDevices.enumerateDevices() will return an empty label attribute value if the permission for accessing the mediadevice is not given. Try using it after getUserMedia.
(async () => {
await navigator.mediaDevices.getUserMedia({audio: true, video: true});
let devices = await navigator.mediaDevices.enumerateDevices();
console.log(devices);
})();
这篇关于navigator.mediaDevices.enumerateDevices()返回空标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!