forked from Aryankpoor/screen-wrec
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript
More file actions
68 lines (53 loc) · 1.96 KB
/
script
File metadata and controls
68 lines (53 loc) · 1.96 KB
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
var video = document.querySelector('.recording');
var output = document.querySelector('.output');
var start = document.querySelector('.start-btn');
var stop = document.querySelector('.stop-btn');
var anc = document.querySelector(".download-anc")
var data = [];
// In order record the screen with system audio
var recording = navigator.mediaDevices.getDisplayMedia({
video: {
mediaSource: 'screen',
},
audio: true,
})
.then(async (e) => {
// For recording the mic audio
let audio = await navigator.mediaDevices.getUserMedia({
audio: true, video: false })
// Assign the recorded mediastream to the src object
video.srcObject = e;
// Combine both video/audio stream with MediaStream object
let combine = new MediaStream(
[...e.getTracks(), ...audio.getTracks()])
/* Record the captured mediastream
with MediaRecorder constructor */
let recorder = new MediaRecorder(combine);
start.addEventListener('click', (e) => {
// Starts the recording when clicked
recorder.start();
alert("recording started")
// For a fresh start
data = []
});
stop.addEventListener('click', (e) => {
// Stops the recording
recorder.stop();
alert("recording stopped")
});
/* Push the recorded data to data array
when data available */
recorder.ondataavailable = (e) => {
data.push(e.data);
};
recorder.onstop = () => {
/* Convert the recorded audio to
blob type mp4 media */
let blobData = new Blob(data, { type: 'video/mp4' });
// Convert the blob data to a url
let url = URL.createObjectURL(blobData)
// Assign the url to the output video tag and anchor
output.src = url
anc.href = url
};
});