-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
120 lines (104 loc) · 3.08 KB
/
index.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta content="Vitals Scanner Web Browser" name="title">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>Vitals Scanner Web Browser</title>
<style>
body {
margin: 30px;
}
h1 {
font-family: sans-serif;
color: #666;
}
#container {
width: 500px;
height: 375px;
border: 10px #333 solid;
}
#videoElement,#camera--sensor {
width: 500px;
height: 375px;
background-color: #666;
}
button {
margin-top: 20px;
font-size: 12px;
font-weight: bold;
padding: 5px;
background-color: white;
border: 5px solid black;
}
button:hover {
background-color: yellow;
}
button:active {
background-color: yellowgreen;
}
</style>
</head>
<body>
<h1>Vitals Scanner Web Browser</h1>
<div id="container">
<!--video autoplay="true" id="videoElement"></video-->
<!-- Camera view -->
<!-- Camera sensor -->
<canvas id="camera--sensor"></canvas>
<video id="videoElement" autoplay playsinline></video>
</div>
<br>
<button id="stop">Stop Video</button>
<br>
<a id="download">Download
<script>
let shouldStop = false;
let stopped = false;
const downloadLink = document.getElementById('download');
const stopButton = document.getElementById('stop');
const cameraView = document.querySelector("#videoElement");
stopButton.addEventListener('click', function() {
shouldStop = true;
console.log("pressed stop button");
handleSuccess(videoElement.srcObject);
})
var handleSuccess = function(stream) {
const options = {mimeType: 'video/webm'};
const recordedChunks = [];
const mediaRecorder = new MediaRecorder(stream, options);
cameraView.srcObject = stream;
mediaRecorder.addEventListener('dataavailable', function(e) {
console.log("output mediaRecorder data");
if (e.data.size > 0) {
recordedChunks.push(e.data);
}
});
mediaRecorder.addEventListener('stop', function() {
console.log("output video stream to URL");
downloadLink.href = URL.createObjectURL(new Blob(recordedChunks));
downloadLink.download = 'vitals_scan.webm';
});
if (shouldStop === true && stopped === false) {
console.log("stop button pressed, ending video stream");
var tracks = stream.getTracks();
for (var i = 0; i < tracks.length; i++) {
var track = tracks[i];
track.stop();
}
videoElement.srcObject = null;
stopped = true;
console.log("video stream ended");
}
else {
console.log("capturing video stream");
mediaRecorder.start();
videoElement.srcObject = stream;
}
};
navigator.mediaDevices.getUserMedia({ audio: false, video: true })
.then(handleSuccess);
window.addEventListener("load", cameraStart, false);
</script>
</body>
</html>