Spaces:
Sleeping
Sleeping
File size: 686 Bytes
6040ae6 67ad67b 6040ae6 db30738 6040ae6 67ad67b db30738 6040ae6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
async function selectLastCamera() {
const devices = await navigator.mediaDevices.enumerateDevices();
const videoDevices = devices.filter(device => device.kind === 'videoinput');
if(videoDevices.length > 0) {
const lastDeviceId = videoDevices[videoDevices.length - 1].deviceId;
const constraints = {
video: { deviceId: { exact: lastDeviceId } }
};
try {
const stream = await navigator.mediaDevices.getUserMedia(constraints);
// Use the stream for your video element
video_source.srcObject = stream;
video_source.play();
} catch(error) {
console.error('Error accessing the camera', error);
}
}
}
selectLastCamera(); |