Skip to content

Commit

Permalink
pauseRecording and resumeRecording methods added. (for StereoAudioRec…
Browse files Browse the repository at this point in the history
  • Loading branch information
muaz-khan committed Jan 29, 2015
1 parent 53335b8 commit cf086ae
Show file tree
Hide file tree
Showing 7 changed files with 217 additions and 13 deletions.
102 changes: 99 additions & 3 deletions RecordRTC.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Last time updated at Jan 21, 2015, 08:32:23
// Last time updated at Jan 29, 2015, 08:32:23

// links:
// Open-Sourced: https://github.com/muaz-khan/RecordRTC
Expand Down Expand Up @@ -183,6 +183,40 @@ function RecordRTC(mediaStream, config) {
}
}

function pauseRecording() {
if (!mediaRecorder) {
return console.warn(WARNING);
}

// not all libs yet having this method
if (mediaRecorder.pause) {
mediaRecorder.pause();

if (!config.disableLogs) {
console.debug('Paused recording.');
}
} else if (!config.disableLogs) {
console.warn('This recording library is having no "pause" method.');
}
}

function resumeRecording() {
if (!mediaRecorder) {
return console.warn(WARNING);
}

// not all libs yet having this method
if (mediaRecorder.resume) {
mediaRecorder.resume();

if (!config.disableLogs) {
console.debug('Resumed recording.');
}
} else if (!config.disableLogs) {
console.warn('This recording library is having no "resume" method.');
}
}

function getDataURL(callback, _mediaRecorder) {
if (!callback) {
throw 'Pass a callback function over getDataURL.';
Expand Down Expand Up @@ -258,10 +292,29 @@ function RecordRTC(mediaStream, config) {
* video.src = videoURL;
* recordRTC.blob; recordRTC.buffer;
* });
* @todo Implement <code class="str">recordRTC.stopRecording().getDataURL(callback);</code>
*/
stopRecording: stopRecording,

/**
* This method pauses the recording process.
* @method
* @memberof RecordRTC
* @instance
* @example
* recordRTC.pauseRecording();
*/
pauseRecording: pauseRecording,

/**
* This method resumes the recording process.
* @method
* @memberof RecordRTC
* @instance
* @example
* recordRTC.resumeRecording();
*/
resumeRecording: resumeRecording,

/**
* It is equivalent to <code class="str">"recordRTC.blob"</code> property.
* @method
Expand Down Expand Up @@ -1193,6 +1246,22 @@ function StereoRecorder(mediaStream) {
});
};

this.pause = function() {
if (!mediaRecorder) {
return;
}

mediaRecorder.pause();
};

this.resume = function() {
if (!mediaRecorder) {
return;
}

mediaRecorder.resume();
};

// Reference to "StereoAudioRecorder" object
var mediaRecorder;
}
Expand Down Expand Up @@ -1540,9 +1609,36 @@ function StereoAudioRecorder(mediaStream, config) {
console.log('buffer-size', bufferSize);
}

var isPaused = false;
/**
* This method pauses the recording process.
* @method
* @memberof StereoAudioRecorder
* @example
* recorder.pause();
*/
this.pause = function() {
isPaused = true;
};

/**
* This method resumes the recording process.
* @method
* @memberof StereoAudioRecorder
* @example
* recorder.resume();
*/
this.resume = function() {
isPaused = false;
};

var isAudioProcessStarted = false;

__stereoAudioRecorderJavacriptNode.onaudioprocess = function(e) {
if (isPaused) {
return;
}

// if MediaStream().stop() or MediaStreamTrack.stop() is invoked.
if (mediaStream.ended) {
__stereoAudioRecorderJavacriptNode.onaudioprocess = function() {};
Expand Down
2 changes: 1 addition & 1 deletion RecordRTC.min.js

Large diffs are not rendered by default.

55 changes: 54 additions & 1 deletion dev/RecordRTC.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,40 @@ function RecordRTC(mediaStream, config) {
}
}

function pauseRecording() {
if (!mediaRecorder) {
return console.warn(WARNING);
}

// not all libs yet having this method
if (mediaRecorder.pause) {
mediaRecorder.pause();

if (!config.disableLogs) {
console.debug('Paused recording.');
}
} else if (!config.disableLogs) {
console.warn('This recording library is having no "pause" method.');
}
}

function resumeRecording() {
if (!mediaRecorder) {
return console.warn(WARNING);
}

// not all libs yet having this method
if (mediaRecorder.resume) {
mediaRecorder.resume();

if (!config.disableLogs) {
console.debug('Resumed recording.');
}
} else if (!config.disableLogs) {
console.warn('This recording library is having no "resume" method.');
}
}

function getDataURL(callback, _mediaRecorder) {
if (!callback) {
throw 'Pass a callback function over getDataURL.';
Expand Down Expand Up @@ -205,10 +239,29 @@ function RecordRTC(mediaStream, config) {
* video.src = videoURL;
* recordRTC.blob; recordRTC.buffer;
* });
* @todo Implement <code class="str">recordRTC.stopRecording().getDataURL(callback);</code>
*/
stopRecording: stopRecording,

/**
* This method pauses the recording process.
* @method
* @memberof RecordRTC
* @instance
* @example
* recordRTC.pauseRecording();
*/
pauseRecording: pauseRecording,

/**
* This method resumes the recording process.
* @method
* @memberof RecordRTC
* @instance
* @example
* recordRTC.resumeRecording();
*/
resumeRecording: resumeRecording,

/**
* It is equivalent to <code class="str">"recordRTC.blob"</code> property.
* @method
Expand Down
27 changes: 27 additions & 0 deletions dev/StereoAudioRecorder.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,9 +342,36 @@ function StereoAudioRecorder(mediaStream, config) {
console.log('buffer-size', bufferSize);
}

var isPaused = false;
/**
* This method pauses the recording process.
* @method
* @memberof StereoAudioRecorder
* @example
* recorder.pause();
*/
this.pause = function() {
isPaused = true;
};

/**
* This method resumes the recording process.
* @method
* @memberof StereoAudioRecorder
* @example
* recorder.resume();
*/
this.resume = function() {
isPaused = false;
};

var isAudioProcessStarted = false;

__stereoAudioRecorderJavacriptNode.onaudioprocess = function(e) {
if (isPaused) {
return;
}

// if MediaStream().stop() or MediaStreamTrack.stop() is invoked.
if (mediaStream.ended) {
__stereoAudioRecorderJavacriptNode.onaudioprocess = function() {};
Expand Down
16 changes: 16 additions & 0 deletions dev/StereoRecorder.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,22 @@ function StereoRecorder(mediaStream) {
});
};

this.pause = function() {
if (!mediaRecorder) {
return;
}

mediaRecorder.pause();
};

this.resume = function() {
if (!mediaRecorder) {
return;
}

mediaRecorder.resume();
};

// Reference to "StereoAudioRecorder" object
var mediaRecorder;
}
2 changes: 1 addition & 1 deletion dev/head.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Last time updated at Jan 21, 2015, 08:32:23
// Last time updated at Jan 29, 2015, 08:32:23

// links:
// Open-Sourced: https://github.com/muaz-khan/RecordRTC
Expand Down
26 changes: 19 additions & 7 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@
</script>

<!-- script used for audio/video/gif recording -->
<script src="//cdn.webrtc-experiment.com/RecordRTC.js">
<script src="https://cdn.webrtc-experiment.com/RecordRTC.js">
</script>
<script src="//cdn.webrtc-experiment.com/gif-recorder.js">
<script src="https://cdn.webrtc-experiment.com/gif-recorder.js">
</script>
</head>

Expand Down Expand Up @@ -87,6 +87,7 @@ <h2 class="header">
<div class="inner" style="height: 5em;">
<audio id="audio" autoplay controls></audio>
<button id="record-audio">Record</button>
<button id="pause-resume-audio" disabled>Pause</button>
<button id="stop-recording-audio" disabled>Stop</button>
<h2 id="audio-url-preview"></h2>
</div>
Expand Down Expand Up @@ -187,6 +188,7 @@ <h2 class="header">Try <a href="https://www.webrtc-experiment.com/RecordRTC/Audi
recordVideo = getByID('record-video'),
recordGIF = getByID('record-gif'),
stopRecordingAudio = getByID('stop-recording-audio'),
pauseResumeAudio = getByID('pause-resume-audio'),
stopRecordingVideo = getByID('stop-recording-video'),
stopRecordingGIF = getByID('stop-recording-gif');

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

audio.src = URL.createObjectURL(audioStream);
audio.muted = true;
audio.play();

// "audio" is a default type
recorder = window.RecordRTC(stream, {
type: 'audio',
bufferSize: typeof params.bufferSize == 'undefined' ? 4096 : params.bufferSize,
bufferSize: typeof params.bufferSize == 'undefined' ? 16384 : params.bufferSize,
sampleRate: typeof params.sampleRate == 'undefined' ? 44100 : params.sampleRate,
leftChannel: params.leftChannel || false,
disableLogs: params.disableLogs || false
Expand All @@ -252,6 +250,7 @@ <h2 class="header">Try <a href="https://www.webrtc-experiment.com/RecordRTC/Audi

this.disabled = true;
stopRecordingAudio.disabled = false;
pauseResumeAudio.disabled = false;
};

var screen_constraints;
Expand Down Expand Up @@ -341,6 +340,19 @@ <h2 class="header">Try <a href="https://www.webrtc-experiment.com/RecordRTC/Audi
document.getElementById('audio-url-preview').innerHTML = '<a href="' + url + '" target="_blank">Recorded Audio URL</a>';
});
};

pauseResumeAudio.onclick = function() {
if(!recorder) return;

if(this.innerHTML === 'Pause') {
this.innerHTML = 'Resume';
recorder.pauseRecording();
return;
}

this.innerHTML = 'Pause';
recorder.resumeRecording();
};

stopRecordingVideo.onclick = function() {
this.disabled = true;
Expand Down

0 comments on commit cf086ae

Please sign in to comment.