Skip to content
Advertisement

Browser permissions for GetUserMedia from different camera devices

In the site I am coding, I want the user to have the option of toggling between different video input devices and view the stream. I am able to enumerate all the devices using navigator.mediaDevices.enumerateDevices() and filtering this by kind gives me the video input devices.

However, when I try to use navigator.mediaDevices.getUserMedia({ video: { deviceId: deviceIdOfSelectedDevice }}), I notice that I only get the stream of the camera allowed by the browser irrespective of the deviceId. I want to prompt for browser permissions to allow a different camera.

Advertisement

Answer

The documentation says this about your code:

The above will return the camera you requested, or a different camera if that specific camera is no longer available.

The document also says that you can require a device with exact:

{ video: { deviceId: { exact: deviceIdOfSelectedDevice } } }
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement