-
Notifications
You must be signed in to change notification settings - Fork 2
/
video.js
50 lines (43 loc) · 1.34 KB
/
video.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
const constraints = { "video": { width: { max: 320 } }, "audio" : true };
var theStream;
var theRecorder;
var recordedChunks = [];
function startFunction() {
navigator.mediaDevices.getUserMedia(constraints)
.then(gotMedia)
.catch(e => { console.error('getUserMedia() failed: ' + e); });
}
function gotMedia(stream) {
theStream = stream;
var video = document.querySelector('video');
video.src = URL.createObjectURL(stream);
try {
recorder = new MediaRecorder(stream, {mimeType : "video/webm"});
} catch (e) {
console.error('Exception while creating MediaRecorder: ' + e);
return;
}
theRecorder = recorder;
recorder.ondataavailable =
(event) => { recordedChunks.push(event.data); };
recorder.start(100);
}
// From @samdutton's "Record Audio and Video with MediaRecorder"
// https://developers.google.com/web/updates/2016/01/mediarecorder
function downloadVideo() {
theRecorder.stop();
theStream.getTracks().forEach(track => { track.stop(); });
var blob = new Blob(recordedChunks, {type: "video/webm"});
var fd = new FormData();
fd.append('fname', 'video.webm');
fd.append('data', blob);
$.ajax({
type: 'POST',
url: 'http://172.16.21.223:3000/api/platform/uploadDocument',
data: fd,
processData: false,
contentType: false
}).done(function (data) {
console.log(data);
});
}