Bruno
Bruno

Reputation: 41

Javascript: Get the browser's selected microphone name

I'm trying to build a function to get the browser's selected microphone name via Javascript. Like if we have several microphones in the system and the browser have one selected, I need to know his name to use it in other functions.

I tryed the getUserMedia method but i can't figure how to get the microphone name with this. And, as I read in some articles there are some incompatibilities with google chrome.

Is there any other way to get this info?

Upvotes: 0

Views: 4569

Answers (1)

bfmags
bfmags

Reputation: 2925

  • navigator.mediaDevices.enumerateDevices()

    mediaDevice.label


navigator.mediaDevices.enumerateDevices()
.then(function(devices) {
  devices.forEach(function(device) {
    console.log(device.kind + ": " + device.label +
            " id = " + device.deviceId);
  });
})

Supported by Chrome 45, Firefox 39


  • MediaStreamTrack.getSources()

Deprecated

MediaStreamTrack.label

MediaStreamTrack.getSources(function(sourceInfos) {
  for (var i = 0; i != sourceInfos.length; ++i) {
    var sourceInfo = sourceInfos[i];
    console.log(sourceInfo.id, sourceInfo.label);
  }
});

Deprecated in Chrome 45, removed in Chrome 47.


getUserMedia MUST be invoked before 'enumerateDevices' or 'getSources' methods


Upvotes: 2

Related Questions