I am working on media control functionality. I am displaying device name to select from a dropdown and it's working fine on chrome but on firefox it will not fetching label or device name.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
navigator.mediaDevices.enumerateDevices()
will return an empty label attribute value in the media device info if the respective permissions are not granted.
To make it work, I placed this function after all of the media permissions have been granted so it returns a label attribute value as well.
回答2:
navigator.mediaDevices.enumerateDevices() returns a promise that's fulfilled with an array of MediaDeviceInfo instances.
It worked for me in Firefox 56.0 (64-bit).
You can do something like this:
navigator.mediaDevices.enumerateDevices()
.then((data) => {
console.log('data', data);
})
.catch((err) => {
console.log('error getting MediaDeviceInfo list', err);
});
where data is the array that contains the list of all MediaDeviceInfo instances.
more info here: https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/enumerateDevices