I would like to use x to output a list of all connected webcams with ID. Unfortunately, I always get the following error message (see picture).
Does anyone have an idea what this could be? I am thankful for any help!
Here is my code:
const devices = [];
var list;
let video;
function setup() {
list = navigator.mediaDevices.enumerateDevices().then(gotDevices);
var constraints1 = {
video: {
deviceId: {
exact: list[0].id
},
}
};
canvas = createCanvas(width,height);
background(255);
video = createCapture(constraints1);
}
function gotDevices(deviceInfos) {
for (let i = 0; i !== deviceInfos.length; ++i) {
const deviceInfo = deviceInfos[i];
if (deviceInfo.kind == 'videoinput') {
devices.push({
label: deviceInfo.label,
id: deviceInfo.deviceId
});
}
}
return devices;
}
-------------------------------EDIT (Current status)-----------------------
var deviceList = [];
function preload() {
navigator.mediaDevices.enumerateDevices().then(getDevices);
}
function setup() {
var constraints = {
video: {
deviceId: {
exact: deviceList[1].id
},
}
};
canvas = createCanvas(width, height);
background(255);
video = createCapture(constraints);
//console.log(deviceList);
}
function getDevices(devices) {
//arrayCopy(devices, deviceList);
for (let i = 0; i < devices.length; ++i) {
let deviceInfo = devices[i];
//Only get videodevices and push them into deviceList
if (deviceInfo.kind == 'videoinput') {
deviceList.push({
label: deviceInfo.label,
id: deviceInfo.deviceId
});
// console.log("Device name :", devices[i].label);
// console.log("DeviceID :", devices[i].deviceId);
}
}
}

The information that you are looking for is down in the 'getDevices' function. The following runs on my system and will show the device name and id in the console window. It will also create a global array for audio and video devices that you may access in setup(); Note that the deviceList is obtained in preload() which is run only once before the rest of your code.
DropDownList of Devices