@@ -17,13 +17,13 @@ let mediaRecorder;
17
17
let recordedBlobs ;
18
18
19
19
const codecPreferences = document . querySelector ( '#codecPreferences' ) ;
20
-
21
20
const errorMsgElement = document . querySelector ( 'span#errorMsg' ) ;
22
21
const recordedVideo = document . querySelector ( 'video#recorded' ) ;
23
22
const recordButton = document . querySelector ( 'button#record' ) ;
24
23
recordButton . addEventListener ( 'click' , ( ) => {
25
24
if ( recordButton . textContent === 'Start Recording' ) {
26
25
startRecording ( ) ;
26
+ uploadButton . disabled = true ;
27
27
} else {
28
28
stopRecording ( ) ;
29
29
recordButton . textContent = 'Start Recording' ;
@@ -33,15 +33,24 @@ recordButton.addEventListener('click', () => {
33
33
}
34
34
} ) ;
35
35
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 ) {
40
37
recordedVideo . src = null ;
41
38
recordedVideo . srcObject = null ;
42
- recordedVideo . src = window . URL . createObjectURL ( superBuffer ) ;
39
+ recordedVideo . src = window . URL . createObjectURL ( blob ) ;
43
40
recordedVideo . controls = true ;
44
41
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 ] ) ;
45
54
} ) ;
46
55
47
56
const downloadButton = document . querySelector ( 'button#download' ) ;
0 commit comments