Skip to content

Commit 75e1db6

Browse files
committed
pauseRecording and resumeRecording methods added. (for StereoAudioRecorder)
https://www.webrtc-experiment.com/RecordRTC/
1 parent 8ca662e commit 75e1db6

File tree

7 files changed

+217
-13
lines changed

7 files changed

+217
-13
lines changed

RecordRTC.js

Lines changed: 99 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Last time updated at Jan 21, 2015, 08:32:23
1+
// Last time updated at Jan 29, 2015, 08:32:23
22

33
// links:
44
// Open-Sourced: https://github.com/muaz-khan/RecordRTC
@@ -183,6 +183,40 @@ function RecordRTC(mediaStream, config) {
183183
}
184184
}
185185

186+
function pauseRecording() {
187+
if (!mediaRecorder) {
188+
return console.warn(WARNING);
189+
}
190+
191+
// not all libs yet having this method
192+
if (mediaRecorder.pause) {
193+
mediaRecorder.pause();
194+
195+
if (!config.disableLogs) {
196+
console.debug('Paused recording.');
197+
}
198+
} else if (!config.disableLogs) {
199+
console.warn('This recording library is having no "pause" method.');
200+
}
201+
}
202+
203+
function resumeRecording() {
204+
if (!mediaRecorder) {
205+
return console.warn(WARNING);
206+
}
207+
208+
// not all libs yet having this method
209+
if (mediaRecorder.resume) {
210+
mediaRecorder.resume();
211+
212+
if (!config.disableLogs) {
213+
console.debug('Resumed recording.');
214+
}
215+
} else if (!config.disableLogs) {
216+
console.warn('This recording library is having no "resume" method.');
217+
}
218+
}
219+
186220
function getDataURL(callback, _mediaRecorder) {
187221
if (!callback) {
188222
throw 'Pass a callback function over getDataURL.';
@@ -258,10 +292,29 @@ function RecordRTC(mediaStream, config) {
258292
* video.src = videoURL;
259293
* recordRTC.blob; recordRTC.buffer;
260294
* });
261-
* @todo Implement <code class="str">recordRTC.stopRecording().getDataURL(callback);</code>
262295
*/
263296
stopRecording: stopRecording,
264297

298+
/**
299+
* This method pauses the recording process.
300+
* @method
301+
* @memberof RecordRTC
302+
* @instance
303+
* @example
304+
* recordRTC.pauseRecording();
305+
*/
306+
pauseRecording: pauseRecording,
307+
308+
/**
309+
* This method resumes the recording process.
310+
* @method
311+
* @memberof RecordRTC
312+
* @instance
313+
* @example
314+
* recordRTC.resumeRecording();
315+
*/
316+
resumeRecording: resumeRecording,
317+
265318
/**
266319
* It is equivalent to <code class="str">"recordRTC.blob"</code> property.
267320
* @method
@@ -1193,6 +1246,22 @@ function StereoRecorder(mediaStream) {
11931246
});
11941247
};
11951248

1249+
this.pause = function() {
1250+
if (!mediaRecorder) {
1251+
return;
1252+
}
1253+
1254+
mediaRecorder.pause();
1255+
};
1256+
1257+
this.resume = function() {
1258+
if (!mediaRecorder) {
1259+
return;
1260+
}
1261+
1262+
mediaRecorder.resume();
1263+
};
1264+
11961265
// Reference to "StereoAudioRecorder" object
11971266
var mediaRecorder;
11981267
}
@@ -1540,9 +1609,36 @@ function StereoAudioRecorder(mediaStream, config) {
15401609
console.log('buffer-size', bufferSize);
15411610
}
15421611

1612+
var isPaused = false;
1613+
/**
1614+
* This method pauses the recording process.
1615+
* @method
1616+
* @memberof StereoAudioRecorder
1617+
* @example
1618+
* recorder.pause();
1619+
*/
1620+
this.pause = function() {
1621+
isPaused = true;
1622+
};
1623+
1624+
/**
1625+
* This method resumes the recording process.
1626+
* @method
1627+
* @memberof StereoAudioRecorder
1628+
* @example
1629+
* recorder.resume();
1630+
*/
1631+
this.resume = function() {
1632+
isPaused = false;
1633+
};
1634+
15431635
var isAudioProcessStarted = false;
1544-
1636+
15451637
__stereoAudioRecorderJavacriptNode.onaudioprocess = function(e) {
1638+
if (isPaused) {
1639+
return;
1640+
}
1641+
15461642
// if MediaStream().stop() or MediaStreamTrack.stop() is invoked.
15471643
if (mediaStream.ended) {
15481644
__stereoAudioRecorderJavacriptNode.onaudioprocess = function() {};

RecordRTC.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dev/RecordRTC.js

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,40 @@ function RecordRTC(mediaStream, config) {
130130
}
131131
}
132132

133+
function pauseRecording() {
134+
if (!mediaRecorder) {
135+
return console.warn(WARNING);
136+
}
137+
138+
// not all libs yet having this method
139+
if (mediaRecorder.pause) {
140+
mediaRecorder.pause();
141+
142+
if (!config.disableLogs) {
143+
console.debug('Paused recording.');
144+
}
145+
} else if (!config.disableLogs) {
146+
console.warn('This recording library is having no "pause" method.');
147+
}
148+
}
149+
150+
function resumeRecording() {
151+
if (!mediaRecorder) {
152+
return console.warn(WARNING);
153+
}
154+
155+
// not all libs yet having this method
156+
if (mediaRecorder.resume) {
157+
mediaRecorder.resume();
158+
159+
if (!config.disableLogs) {
160+
console.debug('Resumed recording.');
161+
}
162+
} else if (!config.disableLogs) {
163+
console.warn('This recording library is having no "resume" method.');
164+
}
165+
}
166+
133167
function getDataURL(callback, _mediaRecorder) {
134168
if (!callback) {
135169
throw 'Pass a callback function over getDataURL.';
@@ -205,10 +239,29 @@ function RecordRTC(mediaStream, config) {
205239
* video.src = videoURL;
206240
* recordRTC.blob; recordRTC.buffer;
207241
* });
208-
* @todo Implement <code class="str">recordRTC.stopRecording().getDataURL(callback);</code>
209242
*/
210243
stopRecording: stopRecording,
211244

245+
/**
246+
* This method pauses the recording process.
247+
* @method
248+
* @memberof RecordRTC
249+
* @instance
250+
* @example
251+
* recordRTC.pauseRecording();
252+
*/
253+
pauseRecording: pauseRecording,
254+
255+
/**
256+
* This method resumes the recording process.
257+
* @method
258+
* @memberof RecordRTC
259+
* @instance
260+
* @example
261+
* recordRTC.resumeRecording();
262+
*/
263+
resumeRecording: resumeRecording,
264+
212265
/**
213266
* It is equivalent to <code class="str">"recordRTC.blob"</code> property.
214267
* @method

dev/StereoAudioRecorder.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,9 +342,36 @@ function StereoAudioRecorder(mediaStream, config) {
342342
console.log('buffer-size', bufferSize);
343343
}
344344

345+
var isPaused = false;
346+
/**
347+
* This method pauses the recording process.
348+
* @method
349+
* @memberof StereoAudioRecorder
350+
* @example
351+
* recorder.pause();
352+
*/
353+
this.pause = function() {
354+
isPaused = true;
355+
};
356+
357+
/**
358+
* This method resumes the recording process.
359+
* @method
360+
* @memberof StereoAudioRecorder
361+
* @example
362+
* recorder.resume();
363+
*/
364+
this.resume = function() {
365+
isPaused = false;
366+
};
367+
345368
var isAudioProcessStarted = false;
346369

347370
__stereoAudioRecorderJavacriptNode.onaudioprocess = function(e) {
371+
if (isPaused) {
372+
return;
373+
}
374+
348375
// if MediaStream().stop() or MediaStreamTrack.stop() is invoked.
349376
if (mediaStream.ended) {
350377
__stereoAudioRecorderJavacriptNode.onaudioprocess = function() {};

dev/StereoRecorder.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,22 @@ function StereoRecorder(mediaStream) {
6161
});
6262
};
6363

64+
this.pause = function() {
65+
if (!mediaRecorder) {
66+
return;
67+
}
68+
69+
mediaRecorder.pause();
70+
};
71+
72+
this.resume = function() {
73+
if (!mediaRecorder) {
74+
return;
75+
}
76+
77+
mediaRecorder.resume();
78+
};
79+
6480
// Reference to "StereoAudioRecorder" object
6581
var mediaRecorder;
6682
}

dev/head.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Last time updated at Jan 21, 2015, 08:32:23
1+
// Last time updated at Jan 29, 2015, 08:32:23
22

33
// links:
44
// Open-Sourced: https://github.com/muaz-khan/RecordRTC

index.html

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@
5353
</script>
5454

5555
<!-- script used for audio/video/gif recording -->
56-
<script src="//cdn.webrtc-experiment.com/RecordRTC.js">
56+
<script src="https://cdn.webrtc-experiment.com/RecordRTC.js">
5757
</script>
58-
<script src="//cdn.webrtc-experiment.com/gif-recorder.js">
58+
<script src="https://cdn.webrtc-experiment.com/gif-recorder.js">
5959
</script>
6060
</head>
6161

@@ -87,6 +87,7 @@ <h2 class="header">
8787
<div class="inner" style="height: 5em;">
8888
<audio id="audio" autoplay controls></audio>
8989
<button id="record-audio">Record</button>
90+
<button id="pause-resume-audio" disabled>Pause</button>
9091
<button id="stop-recording-audio" disabled>Stop</button>
9192
<h2 id="audio-url-preview"></h2>
9293
</div>
@@ -187,6 +188,7 @@ <h2 class="header">Try <a href="https://www.webrtc-experiment.com/RecordRTC/Audi
187188
recordVideo = getByID('record-video'),
188189
recordGIF = getByID('record-gif'),
189190
stopRecordingAudio = getByID('stop-recording-audio'),
191+
pauseResumeAudio = getByID('pause-resume-audio'),
190192
stopRecordingVideo = getByID('stop-recording-video'),
191193
stopRecordingGIF = getByID('stop-recording-gif');
192194

@@ -227,14 +229,10 @@ <h2 class="header">Try <a href="https://www.webrtc-experiment.com/RecordRTC/Audi
227229
if (window.IsChrome) stream = new window.MediaStream(stream.getAudioTracks());
228230
audioStream = stream;
229231

230-
audio.src = URL.createObjectURL(audioStream);
231-
audio.muted = true;
232-
audio.play();
233-
234232
// "audio" is a default type
235233
recorder = window.RecordRTC(stream, {
236234
type: 'audio',
237-
bufferSize: typeof params.bufferSize == 'undefined' ? 4096 : params.bufferSize,
235+
bufferSize: typeof params.bufferSize == 'undefined' ? 16384 : params.bufferSize,
238236
sampleRate: typeof params.sampleRate == 'undefined' ? 44100 : params.sampleRate,
239237
leftChannel: params.leftChannel || false,
240238
disableLogs: params.disableLogs || false
@@ -252,6 +250,7 @@ <h2 class="header">Try <a href="https://www.webrtc-experiment.com/RecordRTC/Audi
252250

253251
this.disabled = true;
254252
stopRecordingAudio.disabled = false;
253+
pauseResumeAudio.disabled = false;
255254
};
256255

257256
var screen_constraints;
@@ -341,6 +340,19 @@ <h2 class="header">Try <a href="https://www.webrtc-experiment.com/RecordRTC/Audi
341340
document.getElementById('audio-url-preview').innerHTML = '<a href="' + url + '" target="_blank">Recorded Audio URL</a>';
342341
});
343342
};
343+
344+
pauseResumeAudio.onclick = function() {
345+
if(!recorder) return;
346+
347+
if(this.innerHTML === 'Pause') {
348+
this.innerHTML = 'Resume';
349+
recorder.pauseRecording();
350+
return;
351+
}
352+
353+
this.innerHTML = 'Pause';
354+
recorder.resumeRecording();
355+
};
344356

345357
stopRecordingVideo.onclick = function() {
346358
this.disabled = true;

0 commit comments

Comments
 (0)