-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrecorder.php
More file actions
188 lines (153 loc) · 5.94 KB
/
recorder.php
File metadata and controls
188 lines (153 loc) · 5.94 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
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>MediaCapture and Streams API</title>
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" href="main.css">
<link href='https://fonts.googleapis.com/css?family=Roboto' rel='stylesheet'>
<link href="https://fonts.googleapis.com/css?family=Open+Sans:400,600,300" rel="stylesheet" type="text/css">
<link href='https://fonts.googleapis.com/css?family=Open Sans' rel='stylesheet'>
<style type="text/css">
video {
width: 640px;
height: 480px;
}
button {
margin: 1em;
padding: 0.7em;
background-color: #000;
color: #00ffff;
border: none;
cursor: pointer;
}
#download {
width: 100vw;
text-align: center;
margin-bottom: 5vh;
}
a {
text-decoration: none;
padding: 5px 15px 5px 15px;
background-color: #000;
color: #00ffff;
font-size: 22px;
}
#vid2 {
margin-left: 5vw;
}
body {
font :16px Open Sans;
}
</style>
</head>
<body>
<header style="display: flex;">
<img src="images/logo6.jpg" style="height: 80px; width: 80px; margin-left: 2vw;"> <span style="margin-left: 2vw;"><h2>Class-ified Recorder</h2></span>
</header>
<main>
<p style="margin-left: 2vw;">Use the <b style="font-size: 19px;">Start</b> button to begin the recording and when you want to finish the recording click <b style="font-size: 19px;">Stop</b> after that you would be able to see a download button through which you can save to your system. <b style="font-size: 19px;">Check</b> your recorded video with the nearby video player.</p>
<video controls muted style="margin-left: 5vw;"></video>
<video id="vid2" controls></video>
<p><button id="btnStart" style="margin-left: 5vw;">START RECORDING</button>
<button id="btnStop" style="margin-left: 5vw;">STOP RECORDING</button></p>
<div id="download">
<a href="#" style="display: none; margin-left: 10vw; margin-right: 10vw;" id="downloadd">Download</a>
</div>
</main>
<script>
const download = document.getElementById('downloadd');
let constraintObj = {
audio: {
echoCancellation: true,
noiseSuppression: true,
sampleRate: 44100
},
video: {
facingMode: "user",
width: { min: 640, ideal: 1280, max: 1920 },
height: { min: 480, ideal: 720, max: 1080 }
}
};
// facingMode: {exact: "user"}
// facingMode: "environment"
//handle older browsers that might implement getUserMedia in some way
if (navigator.mediaDevices === undefined) {
navigator.mediaDevices = {};
navigator.mediaDevices.getUserMedia = function(constraintObj) {
let getUserMedia = navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
if (!getUserMedia) {
return Promise.reject(new Error('getUserMedia is not implemented in this browser'));
}
return new Promise(function(resolve, reject) {
getUserMedia.call(navigator, constraintObj, resolve, reject);
});
}
}else{
navigator.mediaDevices.enumerateDevices()
.then(devices => {
devices.forEach(device=>{
console.log(device.kind.toUpperCase(), device.label);
//, device.deviceId
})
})
.catch(err=>{
console.log(err.name, err.message);
})
}
navigator.mediaDevices.getUserMedia(constraintObj)
.then(function(mediaStreamObj) {
//connect the media stream to the first video element
let video = document.querySelector('video');
if ("srcObject" in video) {
video.srcObject = mediaStreamObj;
} else {
//old version
video.src = window.URL.createObjectURL(mediaStreamObj);
}
video.onloadedmetadata = function(ev) {
//show in the video element what is being captured by the webcam
video.play();
};
//add listeners for saving video/audio
let start = document.getElementById('btnStart');
let stop = document.getElementById('btnStop');
let vidSave = document.getElementById('vid2');
let mediaRecorder = new MediaRecorder(mediaStreamObj);
let chunks = [];
start.addEventListener('click', (ev)=>{
mediaRecorder.start();
console.log(mediaRecorder.state);
})
/*stop.addEventListener('click', (ev)=>{
mediaRecorder.stop();
console.log(mediaRecorder.state);
});*/
stop.addEventListener('click', (ev)=>{
mediaRecorder.stop();
console.log(mediaRecorder.state);
/*download.href = url;
download.download = 'test.mp4';
download.style.display = 'block';
console.log('hai');*/
});
mediaRecorder.ondataavailable = function(ev) {
chunks.push(ev.data);
}
mediaRecorder.onstop = (ev)=>{
let blob = new Blob(chunks, { 'type' : 'video/mp4;' });
chunks = [];
let videoURL = window.URL.createObjectURL(blob);
vidSave.src = videoURL;
download.href = videoURL;
download.download = 'test.mp4';
download.style.display = 'block';
console.log('hai');
}
})
.catch(function(err) {
console.log(err.name, err.message);
});
</script>
</body>
</html>