navigator.mediaDevices.enumerateDevices() returns empty labels

我的未来我决定 提交于 2020-12-30 06:14:00

问题


Background

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)

Issue

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

await navigator.mediaDevices.enumerateDevices()

I get empty labels for available video camera devices.


回答1:


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); 
})();



回答2:


I resolved this issue by just putting my root ca to chrome. It means you should make chome browser recognizing your web server is trustworthy.



来源:https://stackoverflow.com/questions/60297972/navigator-mediadevices-enumeratedevices-returns-empty-labels

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!