deviceId constraint ignored?

Hi,
I’m wanting to use mutliple camera inputs so I’m using the deviceId constraint on createCapture, but it doesnt seem to matter what I enter it will always just uses the first availalbe video source

If device ID isn’t correct should it error out, not capture anything, or just default to first device?

I get the same result in FF and Chrome. Also tried with the groupID constraint and get the same result.

Everything else works as expected, I can set width and height etc in the same section and that works fine.

Anyone know what i might be doing wrong?

Edit: So it seems firefox will just use the camera I allow on the security popup, how do I allow it to use all?

It’s quite tricky. What is the value are you passing to createCapture ? I think you need to first list devices, which perhaps is not implemented yet so you need to use the native API

navigator.mediaDevices.enumerateDevices().then(console.log);

then copy the object from the console (it seems p5.js editor’s console doesn’t show the whole object so you need to open developer tools) and put it inside {video: ...}

createCapture({
  video: {
    "deviceId": "...",
    "kind": "videoinput",
    "label": "",
    "groupId": "..."
  }
})

Here are related issues

Oh my, thank you so much. I feel like an idiot, I had deviceId:… instead of “deviceId”:…

Now it works as expected!

glad that it helped! but effectively {arg: xxx} and {"arg": xxx} are the same so perhaps there was another issue… but I guess it’s fine if it works now

You are right, I changed it back and it still works. :thinking:

Only other thing I can think of was I moved enumerateDevices outside of the setup function, then called the 3x setups after. Not sure why that would make a difference as it was getting all 3 devices before.

Whatever it was I hope this is useful for anyone else that might have the same issue in the future.

1 Like