-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
31 lines (26 loc) · 809 Bytes
/
index.js
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
//
// Video control
//
function switchVideo()
{
if (video.paused)
{
if ( navigator.mediaDevices && navigator.mediaDevices.getUserMedia ) {
const constraints = { video: { width: 1280, height: 720, facingMode: 'user' } };
navigator.mediaDevices.getUserMedia( constraints ).then( function ( stream ) {
video.srcObject = stream;
} ).catch( function ( error ) {
console.error( 'Unable to access the camera/webcam.', error );
} );
} else {
console.error( 'MediaDevices interface not available.' );
}
video.play();
video.style.visibility = 'visible';
} else {
video.style.visibility = 'hidden';
video.srcObject.getTracks()[0].stop();
video.srcObject = null;
}
}
document.getElementById("video_button").onclick = switchVideo;