-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathscreen-recording.html
53 lines (47 loc) · 1.62 KB
/
screen-recording.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Screen Recorder</title>
</head>
<body>
<h1>Screen Recorder</h1>
<button id="start">Start Recording</button>
<button id="stop" disabled>Stop Recording</button>
<video id="recordedVideo" controls></video>
<script>
const startButton = document.getElementById('start');
const stopButton = document.getElementById('stop');
const video = document.getElementById('recordedVideo');
let mediaRecorder;
let recordedChunks = [];
startButton.addEventListener('click', async () => {
const stream = await navigator.mediaDevices.getDisplayMedia({
video: true
});
mediaRecorder = new MediaRecorder(stream);
mediaRecorder.ondataavailable = (event) => {
if (event.data.size > 0) {
recordedChunks.push(event.data);
}
};
mediaRecorder.onstop = () => {
const blob = new Blob(recordedChunks, {
type: 'video/webm'
});
video.src = URL.createObjectURL(blob);
recordedChunks = [];
};
mediaRecorder.start();
startButton.disabled = true;
stopButton.disabled = false;
});
stopButton.addEventListener('click', () => {
mediaRecorder.stop();
startButton.disabled = false;
stopButton.disabled = true;
});
</script>
</body>
</html>