Spaces:
Sleeping
Sleeping
Update static/script.js
Browse files- static/script.js +15 -1
static/script.js
CHANGED
@@ -12,6 +12,7 @@ $(document).ready(function () {
|
|
12 |
$("#banner2").hide(1000);
|
13 |
});
|
14 |
});
|
|
|
15 |
// Function to start the camera capture
|
16 |
function startCamera() {
|
17 |
const videoFeedElement = document.getElementById('video_feed');
|
@@ -29,13 +30,19 @@ function startCamera() {
|
|
29 |
} else {
|
30 |
console.error('getUserMedia is not supported by this browser');
|
31 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
}
|
33 |
|
34 |
// Function to stop the camera
|
35 |
function stopCamera() {
|
36 |
const videoFeedElement = document.getElementById('video_feed');
|
37 |
|
38 |
-
// Stop the video stream by setting source object to null
|
39 |
if (videoFeedElement.srcObject) {
|
40 |
const stream = videoFeedElement.srcObject;
|
41 |
const tracks = stream.getTracks();
|
@@ -48,6 +55,13 @@ function stopCamera() {
|
|
48 |
}
|
49 |
}
|
50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
|
52 |
|
53 |
function startVideo() {
|
|
|
12 |
$("#banner2").hide(1000);
|
13 |
});
|
14 |
});
|
15 |
+
|
16 |
// Function to start the camera capture
|
17 |
function startCamera() {
|
18 |
const videoFeedElement = document.getElementById('video_feed');
|
|
|
30 |
} else {
|
31 |
console.error('getUserMedia is not supported by this browser');
|
32 |
}
|
33 |
+
|
34 |
+
// Update the frames periodically
|
35 |
+
setInterval(function() {
|
36 |
+
if (videoFeedElement.srcObject) {
|
37 |
+
videoFeedElement.srcObject.getVideoTracks().forEach(track => track.requestFrame());
|
38 |
+
}
|
39 |
+
}, 1000 / 30); // Update frames at 30 fps
|
40 |
}
|
41 |
|
42 |
// Function to stop the camera
|
43 |
function stopCamera() {
|
44 |
const videoFeedElement = document.getElementById('video_feed');
|
45 |
|
|
|
46 |
if (videoFeedElement.srcObject) {
|
47 |
const stream = videoFeedElement.srcObject;
|
48 |
const tracks = stream.getTracks();
|
|
|
55 |
}
|
56 |
}
|
57 |
|
58 |
+
// Call the startCamera() function when the "Start Camera" button is clicked
|
59 |
+
document.getElementById('start-camera').addEventListener('click', startCamera);
|
60 |
+
|
61 |
+
// Call the stopCamera() function when the "Stop Camera" button is clicked
|
62 |
+
document.getElementById('stop-camera').addEventListener('click', stopCamera);
|
63 |
+
|
64 |
+
|
65 |
|
66 |
|
67 |
function startVideo() {
|