navigator.mediaDevices.getUserMedia({ video: true, audio: true })
.then(function(stream) {
// Get the list of video tracks (cameras)
var cameras = stream.getVideoTracks();
// Get the list of audio tracks (microphones)
var microphones = stream.getAudioTracks();
// Print the cameras and microphones arrays
console.log('Cameras: ', cameras);
console.log('Microphones: ', microphones);
// Stop the media stream
stream.getTracks().forEach(function(track) {
track.stop();
});
})
.catch(function(error) {
// Access denied or error occurred
console.error('Error accessing media devices: ', error);
});
So above is my code. I am trying to get a list of all of the microphones and video input devices on my device. This code above only seems to get one microphone and one video input device, and I'm not sure why.
I don't think that there are any issues with the devices (I tried on another website that uses webcams and it detected both my built in laptop camera and my USB webcamera), and I get the same results to console with both Edge and Chrome. Everything I've looked up about getUserMedia says that it should get all audio / video devices, but that doesn't seem to happen. Here is the output:
When I unplug my USB device, it prints the built in webcamera that my laptop has. If I plug the USB webcam back in, I only get the USB webcam. Same for the microphone.