Skip to content

Commit b0fa6fd

Browse files
committed
Start 19 Webcam Fun with getVideo; paintToCanvas
1 parent 01103a9 commit b0fa6fd

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

19 - Webcam Fun/scripts.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,25 @@ const canvas = document.querySelector('.photo');
33
const ctx = canvas.getContext('2d');
44
const strip = document.querySelector('.strip');
55
const snap = document.querySelector('.snap');
6+
7+
function getVideo() {
8+
navigator.mediaDevices.getUserMedia(
9+
{video: true, audio: false}
10+
)
11+
.then(localMediaStream => {
12+
video.src = window.URL.createObjectURL(localMediaStream);
13+
video.play();
14+
})
15+
.catch(err => console.error('Danger Will', err));
16+
}
17+
18+
function paintToCanvas() {
19+
const {videoWidth: width, videoHeight: height} = video;
20+
console.log(width, height);
21+
canvas.width = width;
22+
canvas.height = height;
23+
24+
setInterval(() => {
25+
ctx.drawImage(video, 0, 0, width, height);
26+
}, 16);
27+
}

0 commit comments

Comments
 (0)