-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcamera-access.html
45 lines (37 loc) · 1.08 KB
/
camera-access.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction1()">Show Alert</button>
<button onclick="myFunction2()">Open Window</button>
<video id="player" controls autoplay></video>
<button id="capture">Capture</button>
<canvas id="canvas" width=320 height=240></canvas>
<script>
function myFunction1() {
alert("I am an alert box!");
}
function myFunction2() {
window.open("https://www.w3schools.com");
}
const player = document.getElementById('player');
const canvas = document.getElementById('canvas');
const context = canvas.getContext('2d');
const captureButton = document.getElementById('capture');
const constraints = {
video: true,
};
captureButton.addEventListener('click', () => {
// Draw the video frame to the canvas.
context.drawImage(player, 0, 0, canvas.width, canvas.height);
});
// Attach the video stream to the video element and autoplay.
navigator.mediaDevices.getUserMedia(constraints)
.then((stream) => {
player.srcObject = stream;
})
.catch(err =>
document.write(err)
);
</script>
</body>
</html>