Hello everyone, as the title suggests I am having a problem running my javascript code in Processing. However, if I copy this code into the p5.js web editor (https://editor.p5js.org/) the code works without problems. I use the p5.js extension. Maybe someone knows the problem and has a solution how I can fix this and run this code in processing. Thanks a lot!!!
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);
}
}
}
Edit: When I check the developer tools, i get the following error: