Glainez commited on
Commit
db30738
1 Parent(s): dcae7fb

Update select_back_camera.js

Browse files
Files changed (1) hide show
  1. select_back_camera.js +11 -17
select_back_camera.js CHANGED
@@ -1,18 +1,12 @@
1
- window.addEventListener('load', (event) => {
2
- // Wait for Gradio interface to fully load
3
- const gradioAppLoaded = setInterval(() => {
4
- const webcamButton = document.querySelector('button[aria-label="select input source"]');
5
- if (webcamButton) {
6
- clearInterval(gradioAppLoaded);
7
- webcamButton.click();
8
- setTimeout(() => {
9
- const backCameraOption = Array.from(document.querySelectorAll('select option')).find(option => option.text.toLowerCase().includes('0'));
10
- if (backCameraOption) {
11
- backCameraOption.selected = true;
12
- const event = new Event('change', { bubbles: true });
13
- backCameraOption.parentElement.dispatchEvent(event);
14
- }
15
- }, 500); // Adjust timeout as necessary to ensure dropdown is populated
16
- }
17
- }, 1000);
18
  });
 
 
1
+ navigator.mediaDevices.getUserMedia({
2
+ video: { facingMode: "environment" }
3
+ }).then(stream => {
4
+ // Use the stream, for example, attach it to a video element
5
+ let video = document.querySelector('video');
6
+ if (video) {
7
+ video.srcObject = stream;
8
+ }
9
+ }).catch(error => {
10
+ console.error('Error accessing the camera', error);
 
 
 
 
 
 
 
11
  });
12
+