-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathhtml5-webcam.html
62 lines (55 loc) · 1.18 KB
/
html5-webcam.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<style>
body {
margin: 0;
}
#outer {
width: 100vw;
height: 100vh;
}
#inner {
position: absolute;
left: 1em;
top: 1em;
color: white;
font-family: sans-serif;
font-size: xx-large;
font-weight: bold;
}
video {
/* Make video to at least 100% wide and tall */
min-width: 100vw;
min-height: 100vh;
/* Setting width & height to auto prevents the browser from stretching or squishing the video */
width: auto;
height: auto;
/* Center the video */
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
}
</style>
<body>
<div id="outer">
<video id="video" autoplay></video>
<div id="inner">
HTML5 Video
</div>
</div>
</body>
<script>
async function main() {
// Grab elements, create settings, etc.
const video = document.getElementById('video');
// Get access to the camera!
if(navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
// Not adding `{ audio: true }` since we only want video now
const stream = await navigator.mediaDevices.getUserMedia({ video: true });
video.srcObject = stream;
video.onloadedmetadata = () => {
video.play();
};
}
}
main();
</script>