Can't switch device camera on android chrome

It’s currently not possible to switch the device camera on chrome for android. Import the attached package to an empty Unity project, and build it for WebGL(no compression).

Proposed solution:
On the webgl.framework.js file:

1- Go to the function addDevice, change its signature to

function addDevice(label, deviceId) {
    label = label ? label : "device #" + MediaDevices.length;
 
    var device = {
        deviceName: label,
        deviceId: deviceId,
        refCount: 0,
        video: null
    };
    MediaDevices.push(device)
}

2- Not much further below, change the following line:
if (device.kind == “videoinput”) addDevice(device.label) to
if (device.kind == “videoinput”) addDevice(device.label, device.deviceId)
_3-_Finally, on the _JS_WebCamVideo_Start function, change the constraints of the getMedia request to:

video: {deviceId: MediaDevices[deviceId].deviceId},
audio: false

This solution only seem to work the first time. After I refresh the browser, I get the error:

To make it work again, you need to clear the cache and then refresh the browser.

But I guess it’s a good starting point.

6390569–712403–switchCamera.unitypackage (5.31 KB)

1 Like

Notifying that this issue has been taken in implementation in our current development sprint.

2 Likes

@jukka_j Hey Jukka, I’d just like to notify that another bug related to device camera on WebGL is live on the issue tracker. I hadn’t made a forum post for this one.

1 Like

Thanks, that particular one is in my work queue now.