Skip to content

Commit 03ce798

Browse files
authored
More tweaks to switch camera button
1 parent e7512fc commit 03ce798

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

haiku.html

+9-10
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,14 @@
6060
></path>
6161
</g>
6262
</svg></button
63-
><br />
63+
>
6464
<button
6565
id="switchCameraBtn"
6666
style="background-color: transparent; border: none; cursor: pointer"
6767
>
6868
<svg
6969
xmlns="http://www.w3.org/2000/svg"
70-
style="width: 40px; height: 40px"
70+
style="width: 60px; height: 60px"
7171
height="24"
7272
viewBox="0 0 24 24"
7373
fill="none"
@@ -99,14 +99,6 @@
9999
let currentStream;
100100
let currentCamera = "front";
101101

102-
// Show switch button if more than one camera
103-
navigator.mediaDevices.enumerateDevices().then(devices => {
104-
const cameras = devices.filter(device => device.kind === 'videoinput');
105-
if (cameras.length > 1) {
106-
switchCameraBtn.style.display = "block";
107-
}
108-
});
109-
110102
// Request access to the webcam
111103
function startCamera() {
112104
const constraints = {
@@ -119,6 +111,13 @@
119111
.then((stream) => {
120112
currentStream = stream;
121113
video.srcObject = stream;
114+
// Show switch button if more than one camera
115+
navigator.mediaDevices.enumerateDevices().then(devices => {
116+
const cameras = devices.filter(device => device.kind === 'videoinput');
117+
if (cameras.length > 1) {
118+
switchCameraBtn.style.display = "block";
119+
}
120+
});
122121
})
123122
.catch((error) => {
124123
console.error("Error accessing the camera:", error);

0 commit comments

Comments
 (0)