-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcamera.js
More file actions
executable file
·42 lines (32 loc) · 1012 Bytes
/
camera.js
File metadata and controls
executable file
·42 lines (32 loc) · 1012 Bytes
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
window.Camera = {};
Camera.localMediaStream = null;
Camera.play = function(video) {
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia || navigator.msGetUserMedia;
navigator.getUserMedia(
{video: true},
function(stream) {
video.src = window.URL.createObjectURL(stream);
Camera.localMediaStream = stream;
},
function(e) {
console.log('error', e);
});
};
Camera.stop = function() {
Camera.localMediaStream.stop();
}
Camera.createPlayButton = function(video) {
var play = document.createElement('button'),
stop = document.createElement('button');
play.innerHTML = 'play camera';
stop.innerHTML = 'stop camera';
play.addEventListener('click', function () {
Camera.play(video);
}, false);
stop.addEventListener('click', function () {
Camera.stop();
}, false);
document.body.appendChild(play);
document.body.appendChild(stop);
};