0

I want to select which camera to use. I ve found that exists: enumerateDevices()

https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/enumerateDevices

if (!navigator.mediaDevices || !navigator.mediaDevices.enumerateDevices) {
  console.log("enumerateDevices() not supported.");
  return;
}

// List cameras and microphones.

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

I have tried but it doesnt return any camera device.

1 Answer 1

0

I tested your code, it works fine. it returns the mediaDevices list to me.

audioinput: id = default
audioinput: id = communications
audioinput: id = 59392f81738870b09dec51e4375320b0a0ae2f7c44a2683272491e708c3c5cf4
videoinput: id = ae367efe808e935504983bda9831593a5324b3d5e9b79f8801eb9d9d55406531
 audiooutput: id = default
 audiooutput: id = communications
 audiooutput: id = 65235ec7e9c60747b6c24f3de8305f2ceead65432841a7706d57dae87412e1b

I just have an error that appears in your "if" : "Illegal return statement". You have to remove the return.

if (!navigator.mediaDevices ||!navigator.mediaDevices.enumerateDevices) {
  console.log ("enumerateDevices () not supported.");
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.