最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Why does mediaDevices.enumerateDevices list some devices twice? What is default? - Stack Overflow

programmeradmin4浏览0评论

I write this code in JavaScript in Chrome:

navigator.mediaDevices.enumerateDevices()
  .then((list) => {
    console.log(list);
  });

This outputs a list of media devices like microphones and cameras. Each device is represented as an object with its own deviceId. But some devices, like one of the microphones in particular, are listed twice. And one time their respective deviceId is set to 'default'. What is so special about a one default microphone? And how do I tell which actual deviceId it has?

I write this code in JavaScript in Chrome:

navigator.mediaDevices.enumerateDevices()
  .then((list) => {
    console.log(list);
  });

This outputs a list of media devices like microphones and cameras. Each device is represented as an object with its own deviceId. But some devices, like one of the microphones in particular, are listed twice. And one time their respective deviceId is set to 'default'. What is so special about a one default microphone? And how do I tell which actual deviceId it has?

Share Improve this question asked Nov 14, 2018 at 16:39 GhermanGherman 7,43612 gold badges53 silver badges79 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 16

A deviceId lets web sites manage which device their user is using. E.g. store it in a cookie to remember the user's preference from last time.

Some browsers (Chrome, Opera) list the same microphone twice, with different ids. In my case:

  1. Default - Internal Microphone (Built-in)
  2. Internal Microphone (Built-in)

The former is "the OS default", whatever the end-user has configured in System Preferences/Sound (OSX) or Control Panel/Sound (Windows). The idea is: when recalled from a cookie and used, its id gets you whatever is configured in the OS at the time of use, which may differ from last time.

The latter is always the specific mic. Their groupIds match; they're the same physical device atm.

The deviceId = "default" is an oddity of Chrome (and Opera). AFAICT it's a valid id like any other. If you want the other one, pare their groupIds to find it.

Safari does not do this. Firefox recently stopped doing it (as of version 63).

Cameras are never duplicated in this way.

发布评论

评论列表(0)

  1. 暂无评论