Spaces:
Sleeping
Sleeping
Update select_back_camera.js
Browse files- select_back_camera.js +18 -12
select_back_camera.js
CHANGED
@@ -1,16 +1,22 @@
|
|
1 |
-
async function
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
try {
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
video_source.play();
|
10 |
-
// Other setup code as needed
|
11 |
-
} catch (err) {
|
12 |
-
// Error handling
|
13 |
}
|
|
|
14 |
}
|
15 |
|
16 |
-
|
|
|
1 |
+
async function selectLastCamera() {
|
2 |
+
const devices = await navigator.mediaDevices.enumerateDevices();
|
3 |
+
const videoDevices = devices.filter(device => device.kind === 'videoinput');
|
4 |
+
|
5 |
+
if(videoDevices.length > 0) {
|
6 |
+
const lastDeviceId = videoDevices[videoDevices.length - 1].deviceId;
|
7 |
+
const constraints = {
|
8 |
+
video: { deviceId: { exact: lastDeviceId } }
|
9 |
+
};
|
10 |
+
|
11 |
try {
|
12 |
+
const stream = await navigator.mediaDevices.getUserMedia(constraints);
|
13 |
+
// Use the stream for your video element
|
14 |
+
video_source.srcObject = stream;
|
15 |
+
video_source.play();
|
16 |
+
} catch(error) {
|
17 |
+
console.error('Error accessing the camera', error);
|
|
|
|
|
|
|
|
|
18 |
}
|
19 |
+
}
|
20 |
}
|
21 |
|
22 |
+
selectLastCamera();
|