@@ -7,7 +7,7 @@ <h1>ConcatenateBlobs | JavaScript - <a href="https://github.com/muaz-khan/Concat
7
7
</ blockquote >
8
8
9
9
< style >
10
- button {
10
+ button , select {
11
11
font-family : Myriad, Arial, Verdana;
12
12
font-weight : normal;
13
13
border-top-left-radius : 3px ;
@@ -23,10 +23,16 @@ <h1>ConcatenateBlobs | JavaScript - <a href="https://github.com/muaz-khan/Concat
23
23
background : -webkit-gradient (linear, 0% 0% , 0% 100% , color-stop (0.05 , rgb (241 , 241 , 241 )), to (rgb (230 , 230 , 230 )));
24
24
font-size : 20px ;
25
25
border : 1px solid red;
26
+ outline : none;
26
27
}
27
- button [disabled ] {
28
- background : rgba (216 , 205 , 205 , 0.2 );
29
- border : 1px solid rgb (233 , 224 , 224 );
28
+ button : active , button : focus , select : active {
29
+ background : -webkit-gradient (linear, 0% 0% , 0% 100% , color-stop (5% , rgb (221 , 221 , 221 )), to (rgb (250 , 250 , 250 )));
30
+ border : 1px solid rgb (142 , 142 , 142 );
31
+ }
32
+ button [disabled ], select [disabled ] {
33
+ background : rgb (249 , 249 , 249 );
34
+ border : 1px solid rgb (218 , 207 , 207 );
35
+ color : rgb (197 , 189 , 189 );
30
36
}
31
37
blockquote {
32
38
font-size : 20px ;
@@ -52,13 +58,17 @@ <h1>ConcatenateBlobs | JavaScript - <a href="https://github.com/muaz-khan/Concat
52
58
</ p >
53
59
< hr />
54
60
55
- < audio controls > </ audio >
61
+ < select >
62
+ < option > Audio</ option >
63
+ < option > Video</ option >
64
+ </ select > < br > < br >
65
+ < audio controls data-type ="audio/wav "> </ audio >
56
66
57
67
< script src ="https://cdn.webrtc-experiment.com/RecordRTC.js " autoplay > </ script >
58
68
< script src ="https://cdn.webrtc-experiment.com/ConcatenateBlobs.js " autoplay > </ script >
59
69
60
70
< script >
61
- var audio = document . querySelector ( 'audio' ) ;
71
+ var mediaElement = document . querySelector ( 'audio' ) ;
62
72
63
73
var recordRTC ;
64
74
var allBlobs = [ ] ;
@@ -68,14 +78,18 @@ <h1>ConcatenateBlobs | JavaScript - <a href="https://github.com/muaz-khan/Concat
68
78
document . querySelector ( '#concatenateBlobs' ) . disabled = true ;
69
79
70
80
navigator . getUserMedia ( {
71
- audio : true
81
+ audio : mediaElement . getAttribute ( 'data-type' ) == 'audio/wav' ,
82
+ video : mediaElement . getAttribute ( 'data-type' ) == 'video/webm'
72
83
} , function ( stream ) {
73
84
localMediaStream = stream ;
74
85
75
- audio . src = URL . createObjectURL ( stream ) ;
76
- audio . play ( ) ;
86
+ mediaElement . src = URL . createObjectURL ( stream ) ;
87
+ mediaElement . play ( ) ;
77
88
78
- recordRTC = RecordRTC ( stream ) ;
89
+ recordRTC = RecordRTC ( stream , {
90
+ type : mediaElement . getAttribute ( 'data-type' ) == 'audio/wav' ? 'audio' : 'video' ,
91
+ video : mediaElement
92
+ } ) ;
79
93
recordRTC . startRecording ( ) ;
80
94
81
95
document . querySelector ( '#stopRecording' ) . disabled = false ;
@@ -108,11 +122,11 @@ <h1>ConcatenateBlobs | JavaScript - <a href="https://github.com/muaz-khan/Concat
108
122
109
123
var parent = output . parentNode ;
110
124
parent . innerHTML = 'Concatenating ' + allBlobs . length + ' blobs.' ;
111
- ConcatenateBlobs ( allBlobs , 'audio/wav' , function ( resultingBlob ) {
125
+ ConcatenateBlobs ( allBlobs , mediaElement . getAttribute ( 'data-type' ) , function ( resultingBlob ) {
112
126
parent . innerHTML = 'Concatenated. Resulting blob size: <span>' + bytesToSize ( resultingBlob . size ) + '</span>. Playing-back locally in <audio> tag.' ;
113
127
114
- audio . src = URL . createObjectURL ( resultingBlob ) ;
115
- audio . play ( ) ;
128
+ mediaElement . src = URL . createObjectURL ( resultingBlob ) ;
129
+ mediaElement . play ( ) ;
116
130
} ) ;
117
131
} ;
118
132
@@ -126,6 +140,24 @@ <h1>ConcatenateBlobs | JavaScript - <a href="https://github.com/muaz-khan/Concat
126
140
var i = parseInt ( Math . floor ( Math . log ( bytes ) / Math . log ( k ) ) , 10 ) ;
127
141
return ( bytes / Math . pow ( k , i ) ) . toPrecision ( 3 ) + ' ' + sizes [ i ] ;
128
142
}
143
+
144
+ document . querySelector ( 'select' ) . onchange = function ( ) {
145
+ if ( this . value == 'Video' ) {
146
+ var video = document . createElement ( 'video' ) ;
147
+ video . setAttribute ( 'data-type' , 'video/webm' ) ;
148
+ video . setAttribute ( 'controls' , 'true' ) ;
149
+ mediaElement . parentNode . replaceChild ( video , mediaElement ) ;
150
+ mediaElement = video ;
151
+ }
152
+
153
+ if ( this . value == 'Audio' ) {
154
+ var video = document . createElement ( 'audio' ) ;
155
+ video . setAttribute ( 'data-type' , 'audio/wav' ) ;
156
+ video . setAttribute ( 'controls' , 'true' ) ;
157
+ mediaElement . parentNode . replaceChild ( video , mediaElement ) ;
158
+ mediaElement = video ;
159
+ }
160
+ } ;
129
161
</ script >
130
162
131
163
< h2 > How to use?</ h2 >
0 commit comments