Skip to content

Commit

Permalink
Fixed #41 - i.e. now you can reuse "recordRTC" instance.
Browse files Browse the repository at this point in the history
var recordRTC = RecordRTC(audioStream)[
recordRTC.startRecording();

// after some time
recordRTC.stopRecording(function() {
      // blob or URL
});

// after some time
recordRTC.startRecording(); // again start
recordRTC.stopRecording(callback);

recordRTC.startRecording(); // again start
….and so on
  • Loading branch information
muaz-khan committed Sep 26, 2015
1 parent 9de87e7 commit 0a266f4
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 38 deletions.
2 changes: 1 addition & 1 deletion RecordRTC-to-PHP/index.html
Expand Up @@ -194,7 +194,7 @@ <h2 class="header">
}

if(button.recordRTC) {
if(button.recordRTC.length) {
if(button.recordRTC.length && button.RecordRTC instanceof Array) {
button.recordRTC[0].stopRecording(function(url) {
if(!button.recordRTC[1]) {
button.recordingEndedCallback(url);
Expand Down
66 changes: 49 additions & 17 deletions RecordRTC.js
@@ -1,4 +1,4 @@
// Last time updated at September 18, 2015
// Last time updated at September 26, 2015

// links:
// Open-Sourced: https://github.com/muaz-khan/RecordRTC
Expand All @@ -9,6 +9,7 @@

// updates?
/*
-. Now you can reuse single RecordRTC object i.e. stop/start/stop/start/ and so on.
-. GifRecorder.js can now record HTMLCanvasElement|CanvasRenderingContext2D as well.
-. added: frameInterval:20 for WhammyRecorder.js
-. chrome issue audio plus 720p-video recording can be fixed by setting bufferSize:16384
Expand Down Expand Up @@ -53,12 +54,12 @@
// 3. Cross-Browser-Declarations.js
// 4. Storage.js
// 5. MediaStreamRecorder.js
// 7. StereoAudioRecorder.js
// 8. CanvasRecorder.js
// 9. WhammyRecorder.js
// 10. Whammy.js
// 11. DiskStorage.js
// 12. GifRecorder.js
// 6. StereoAudioRecorder.js
// 7. CanvasRecorder.js
// 8. WhammyRecorder.js
// 9. Whammy.js
// 10. DiskStorage.js
// 11. GifRecorder.js
//------------------------------------

'use strict';
Expand Down Expand Up @@ -1516,6 +1517,18 @@ function StereoAudioRecorder(mediaStream, config) {
console.debug('StereoAudioRecorder is set to record number of channels: ', numberOfAudioChannels);
}

function isMediaStreamActive() {
if ('active' in mediaStream) {
if (!mediaStream.active) {
return false;
}
} else if ('ended' in mediaStream) { // old hack
if (mediaStream.ended) {
return false;
}
}
}

/**
* This method records MediaStream.
* @method
Expand All @@ -1524,10 +1537,22 @@ function StereoAudioRecorder(mediaStream, config) {
* recorder.record();
*/
this.record = function() {
if (isMediaStreamActive() === false) {
throw 'Please make sure MediaStream is active.';
}

// reset the buffers for the new recording
leftchannel.length = rightchannel.length = 0;
recordingLength = 0;

if (audioInput) {
audioInput.connect(jsAudioNode);
}

// to prevent self audio to be connected with speakers
// jsAudioNode.connect(context.destination);

isAudioProcessStarted = isPaused = false;
recording = true;
};

Expand Down Expand Up @@ -1878,6 +1903,18 @@ function StereoAudioRecorder(mediaStream, config) {
* recorder.resume();
*/
this.resume = function() {
if (isMediaStreamActive() === false) {
throw 'Please make sure MediaStream is active.';
}

if (!recording) {
if (!config.disableLogs) {
console.info('Seems recording has been restarted.');
}
this.record();
return;
}

isPaused = false;

if (!config.disableLogs) {
Expand Down Expand Up @@ -1910,17 +1947,12 @@ function StereoAudioRecorder(mediaStream, config) {
return;
}

// if MediaStream().stop() or MediaStreamTrack.stop() is invoked.
if ('active' in mediaStream) {
if (!mediaStream.active) {
jsAudioNode.onaudioprocess = function() {};
recording = false;
}
} else if ('ended' in mediaStream) { // old hack
if (mediaStream.ended) {
jsAudioNode.onaudioprocess = function() {};
recording = false;
if (isMediaStreamActive() === false) {
if (!config.disableLogs) {
console.error('MediaStream seems stopped.');
}
jsAudioNode.disconnect();
recording = false;
}

if (!recording) {
Expand Down
4 changes: 2 additions & 2 deletions RecordRTC.min.js

Large diffs are not rendered by default.

51 changes: 41 additions & 10 deletions dev/StereoAudioRecorder.js
Expand Up @@ -52,6 +52,18 @@ function StereoAudioRecorder(mediaStream, config) {
console.debug('StereoAudioRecorder is set to record number of channels: ', numberOfAudioChannels);
}

function isMediaStreamActive() {
if ('active' in mediaStream) {
if (!mediaStream.active) {
return false;
}
} else if ('ended' in mediaStream) { // old hack
if (mediaStream.ended) {
return false;
}
}
}

/**
* This method records MediaStream.
* @method
Expand All @@ -60,10 +72,22 @@ function StereoAudioRecorder(mediaStream, config) {
* recorder.record();
*/
this.record = function() {
if (isMediaStreamActive() === false) {
throw 'Please make sure MediaStream is active.';
}

// reset the buffers for the new recording
leftchannel.length = rightchannel.length = 0;
recordingLength = 0;

if (audioInput) {
audioInput.connect(jsAudioNode);
}

// to prevent self audio to be connected with speakers
// jsAudioNode.connect(context.destination);

isAudioProcessStarted = isPaused = false;
recording = true;
};

Expand Down Expand Up @@ -414,6 +438,18 @@ function StereoAudioRecorder(mediaStream, config) {
* recorder.resume();
*/
this.resume = function() {
if (isMediaStreamActive() === false) {
throw 'Please make sure MediaStream is active.';
}

if (!recording) {
if (!config.disableLogs) {
console.info('Seems recording has been restarted.');
}
this.record();
return;
}

isPaused = false;

if (!config.disableLogs) {
Expand Down Expand Up @@ -446,17 +482,12 @@ function StereoAudioRecorder(mediaStream, config) {
return;
}

// if MediaStream().stop() or MediaStreamTrack.stop() is invoked.
if ('active' in mediaStream) {
if (!mediaStream.active) {
jsAudioNode.onaudioprocess = function() {};
recording = false;
}
} else if ('ended' in mediaStream) { // old hack
if (mediaStream.ended) {
jsAudioNode.onaudioprocess = function() {};
recording = false;
if (isMediaStreamActive() === false) {
if (!config.disableLogs) {
console.error('MediaStream seems stopped.');
}
jsAudioNode.disconnect();
recording = false;
}

if (!recording) {
Expand Down
15 changes: 8 additions & 7 deletions dev/head.js
@@ -1,4 +1,4 @@
// Last time updated at September 18, 2015
// Last time updated at September 26, 2015

// links:
// Open-Sourced: https://github.com/muaz-khan/RecordRTC
Expand All @@ -9,6 +9,7 @@

// updates?
/*
-. Now you can reuse single RecordRTC object i.e. stop/start/stop/start/ and so on.
-. GifRecorder.js can now record HTMLCanvasElement|CanvasRenderingContext2D as well.
-. added: frameInterval:20 for WhammyRecorder.js
-. chrome issue audio plus 720p-video recording can be fixed by setting bufferSize:16384
Expand Down Expand Up @@ -53,12 +54,12 @@
// 3. Cross-Browser-Declarations.js
// 4. Storage.js
// 5. MediaStreamRecorder.js
// 7. StereoAudioRecorder.js
// 8. CanvasRecorder.js
// 9. WhammyRecorder.js
// 10. Whammy.js
// 11. DiskStorage.js
// 12. GifRecorder.js
// 6. StereoAudioRecorder.js
// 7. CanvasRecorder.js
// 8. WhammyRecorder.js
// 9. Whammy.js
// 10. DiskStorage.js
// 11. GifRecorder.js
//------------------------------------

'use strict';
2 changes: 1 addition & 1 deletion index.html
Expand Up @@ -192,7 +192,7 @@ <h2 class="header">
}

if(button.recordRTC) {
if(button.recordRTC.length) {
if(button.recordRTC.length && button.RecordRTC instanceof Array) {
button.recordRTC[0].stopRecording(function(url) {
if(!button.recordRTC[1]) {
button.recordingEndedCallback(url);
Expand Down

0 comments on commit 0a266f4

Please sign in to comment.