-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathWebcam.js
More file actions
66 lines (49 loc) · 1.89 KB
/
Webcam.js
File metadata and controls
66 lines (49 loc) · 1.89 KB
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
63
64
65
var myVideoStream = document.getElementById('myVideo') // make it a global variable
var myStoredInterval = 0
function getVideo(){
navigator.getMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;
navigator.getMedia({video: true, audio: true},
function(stream) {
myVideoStream.srcObject = stream
myVideoStream.play();
},
function(error) {
alert('webcam not working');
});
}
/*
function breakVideo(){
navigator.getMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;
navigator.getMedia({video: false, audio: true},
function(stream) {
myVideoStream.srcObject = stream
myVideoStream.remove;
},
function(error) {
alert('webcam not working');
});
}
function breakAudio(){
navigator.getMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;
navigator.getMedia({video: true, audio: false},
function(stream) {
myVideoStream.srcObject = stream
myVideoStream.play();
},
function(error) {
alert('webcam not working');
});
}
*/
function takeSnapshot() {
var myCanvasElement = document.getElementById('myCanvas');
var myCTX = myCanvasElement.getContext('2d');
myCTX.drawImage(myVideoStream, 0, 0, myCanvasElement.width, myCanvasElement.height);
}
function takeAuto() {
takeSnapshot() // get snapshot right away then wait and repeat
clearInterval(myStoredInterval)
myStoredInterval = setInterval(function(){
takeSnapshot()
}, document.getElementById('myInterval').value);
}