-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecorder.js
49 lines (43 loc) · 1.24 KB
/
recorder.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
let recording = false;
let mediaRecorder;
let recordings = new Object();
let recordedChunksDic = new Object();
function startRecording(recordingName)
{
console.log("Starting the recording with name: " + recordingName);
const stream = outputCanvas.captureStream(25);
recordings[recordingName] = new MediaRecorder(stream, {
mimeType: 'video/webm;codecs=vp8',
ignoreMutedMedia: true
});
recordedChunksDic[recordingName] = [];
recordings[recordingName].ondataavailable = e => {
if(e.data.size > 0){
recordedChunksDic[recordingName].push(e.data);
}
};
recordings[recordingName].start();
}
function stopRecording(recordingName)
{
console.log("Stopping the recording with name " + recordingName);
recordings[recordingName].stop();
}
function viewRecording(recordingName)
{
setTimeout(() => {
let blob = getBlob(recordingName)
const url = URL.createObjectURL(blob);
const video = document.createElement("video");
video.src = url;
video.id = recordingName;
document.body.appendChild(video);
},0);
}
function getBlob(recordingName)
{
const blob = new Blob(recordedChunksDic[recordingName], {
type: "video/webm"
});
return blob;
}