-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhello.html
102 lines (92 loc) · 3.51 KB
/
hello.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
<!DOCTYPE html>
<html>
<head>
<title>RecordRTC with timeSlice, Delay, Loop Playback, and Half Speed</title>
<script src="https://cdn.webrtc-experiment.com/RecordRTC.js"></script>
<style>
body {
margin: 0;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
overflow: hidden;
}
video {
width: 100%;
height: auto;
max-height: calc(100vh - 60px); /* Adjust to ensure buttons are visible */
}
.controls {
margin-top: 10px;
display: flex;
gap: 10px;
}
a {
display: block;
margin-top: 10px;
}
</style>
</head>
<body>
<video id="video" controls autoplay></video>
<div class="controls">
<button id="startRecording">Start Recording</button>
<button id="stopRecording" disabled>Stop Recording</button>
</div>
<a id="downloadLink" style="display:none;">Download Video</a>
<script>
let video = document.getElementById('video');
let startRecordingButton = document.getElementById('startRecording');
let stopRecordingButton = document.getElementById('stopRecording');
let downloadLink = document.getElementById('downloadLink');
let recorder;
let stream;
let recordedBlobs = [];
startRecordingButton.onclick = async () => {
stream = await navigator.mediaDevices.getUserMedia({ video: true, audio: true });
video.srcObject = stream;
recorder = new RecordRTC(stream, {
type: 'video',
timeSlice: 1000, // 1 second
ondataavailable: (blob) => {
recordedBlobs.push(blob);
}
});
recorder.startRecording();
startRecordingButton.disabled = true;
stopRecordingButton.disabled = false;
};
stopRecordingButton.onclick = () => {
stopRecordingButton.disabled = true;
// Delay stopping the recording by 3 seconds
setTimeout(() => {
recorder.stopRecording(() => {
// Combine all recorded blobs into one
let superBuffer = new Blob(recordedBlobs, { type: 'video/webm' });
let url = URL.createObjectURL(superBuffer);
downloadLink.href = url;
downloadLink.download = 'recorded-video.webm';
downloadLink.style.display = 'block';
video.srcObject = null;
video.src = url;
// Set up the video to start playing 5 seconds before the end of the recording at half speed
video.onloadedmetadata = () => {
if (video.duration > 5) {
video.currentTime = video.duration - 5;
}
video.playbackRate = 0.5; // Set playback speed to half
};
video.onended = () => {
video.currentTime = video.duration > 5 ? video.duration - 5 : 0;
video.play();
};
stream.getTracks().forEach(track => track.stop());
startRecordingButton.disabled = false;
});
}, 3000); // 3000 milliseconds delay
};
</script>
</body>
</html>