Skip to content

Commit 9d87f18

Browse files
authored
Merge pull request #1700 from fippo/recording-import
recording: allow local upload and play
2 parents 17550cf + a3cb507 commit 9d87f18

File tree

3 files changed

+36
-6
lines changed

3 files changed

+36
-6
lines changed

src/content/getusermedia/record/css/main.css

+20
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,22 @@
1212
width: 120px;
1313
}
1414

15+
/* copied from main button style */
16+
.file-upload {
17+
background-color: #d84a38;
18+
border: none;
19+
border-radius: 2px;
20+
color: white;
21+
font-family: 'Roboto', sans-serif;
22+
font-size: 0.8em;
23+
margin: 0 0 1em 0;
24+
padding: 0.5em 0.7em 0.6em 0.7em;
25+
}
26+
27+
.file-upload:hover {
28+
background-color: #cf402f;
29+
}
30+
1531
button:last-of-type {
1632
margin: 0;
1733
}
@@ -35,3 +51,7 @@ video:last-of-type {
3551
video#gumVideo {
3652
margin: 0 20px 20px 0;
3753
}
54+
55+
input[type="file"] {
56+
display: none;
57+
}

src/content/getusermedia/record/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ <h1><a href="//webrtc.github.io/samples/" title="WebRTC samples homepage">WebRTC
4949
<button id="record" disabled>Start Recording</button>
5050
<button id="play" disabled>Play</button>
5151
<button id="download" disabled>Download</button>
52+
<label for="upload" class="file-upload">upload locally</label><input id="upload" type="file"/>
5253
</div>
5354

5455
<div>

src/content/getusermedia/record/js/main.js

+15-6
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ let mediaRecorder;
1717
let recordedBlobs;
1818

1919
const codecPreferences = document.querySelector('#codecPreferences');
20-
2120
const errorMsgElement = document.querySelector('span#errorMsg');
2221
const recordedVideo = document.querySelector('video#recorded');
2322
const recordButton = document.querySelector('button#record');
2423
recordButton.addEventListener('click', () => {
2524
if (recordButton.textContent === 'Start Recording') {
2625
startRecording();
26+
uploadButton.disabled = true;
2727
} else {
2828
stopRecording();
2929
recordButton.textContent = 'Start Recording';
@@ -33,15 +33,24 @@ recordButton.addEventListener('click', () => {
3333
}
3434
});
3535

36-
const playButton = document.querySelector('button#play');
37-
playButton.addEventListener('click', () => {
38-
const mimeType = codecPreferences.options[codecPreferences.selectedIndex].value.split(';', 1)[0];
39-
const superBuffer = new Blob(recordedBlobs, {type: mimeType});
36+
function doPlay(blob) {
4037
recordedVideo.src = null;
4138
recordedVideo.srcObject = null;
42-
recordedVideo.src = window.URL.createObjectURL(superBuffer);
39+
recordedVideo.src = window.URL.createObjectURL(blob);
4340
recordedVideo.controls = true;
4441
recordedVideo.play();
42+
};
43+
44+
const playButton = document.querySelector('button#play');
45+
playButton.addEventListener('click', () => {
46+
const mimeType = codecPreferences.options[codecPreferences.selectedIndex].value.split(';', 1)[0];
47+
const superBuffer = new Blob(recordedBlobs, {type: mimeType});
48+
doPlay(superBuffer);
49+
});
50+
51+
const uploadButton = document.querySelector('#upload');
52+
uploadButton.addEventListener('change', e => {
53+
doPlay(e.target.files[0]);
4554
});
4655

4756
const downloadButton = document.querySelector('button#download');

0 commit comments

Comments
 (0)