Skip to content

Commit

Permalink
Merge pull request #128 from thijstriemstra/master
Browse files Browse the repository at this point in the history
add pause/resume recording to MRecordRTC
  • Loading branch information
muaz-khan committed May 11, 2016
2 parents beddb4d + 4dd65b7 commit 56a7afb
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 50 deletions.
90 changes: 66 additions & 24 deletions RecordRTC.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

// Last time updated: 2016-05-11 3:47:57 AM UTC
// Last time updated: 2016-05-11 11:37:50 AM UTC

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

Expand All @@ -24,7 +24,7 @@
* type: 'video' // audio or video or gif or canvas
* });
*
* // or, you can even use keyword "new"
* // or, you can also use the "new" keyword
* var recordRTC = new RecordRTC(mediaStream[, config]);
* @see For further information:
* @see {@link https://github.com/muaz-khan/RecordRTC|RecordRTC Source Code}
Expand Down Expand Up @@ -157,7 +157,7 @@ function RecordRTC(mediaStream, config) {
return console.warn(WARNING);
}

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

if (!config.disableLogs) {
Expand All @@ -178,7 +178,7 @@ function RecordRTC(mediaStream, config) {

if (!blob) {
if (!config.disableLogs) {
console.warn('Blob encoder did not yet finished its job.');
console.warn('Blob encoder did not finish its job yet.');
}

setTimeout(function() {
Expand Down Expand Up @@ -228,7 +228,7 @@ function RecordRTC(mediaStream, config) {

var returnObject = {
/**
* This method starts recording. It doesn't take any argument.
* This method starts recording. It doesn't take any arguments.
* @method
* @memberof RecordRTC
* @instance
Expand All @@ -238,7 +238,7 @@ function RecordRTC(mediaStream, config) {
startRecording: startRecording,

/**
* This method stops recording. It takes single "callback" argument. It is suggested to get blob or URI in the callback to make sure all encoders finished their jobs.
* This method stops recording. It takes a single "callback" argument. It is suggested to get blob or URI in the callback to make sure all encoders finished their jobs.
* @param {function} callback - This callback function is invoked after completion of all encoding jobs.
* @method
* @memberof RecordRTC
Expand Down Expand Up @@ -282,12 +282,12 @@ function RecordRTC(mediaStream, config) {
initRecorder: initRecorder,

/**
* This method initializes the recording process.
* This method sets the recording duration.
* @method
* @memberof RecordRTC
* @instance
* @example
* recordRTC.initRecorder();
* recordRTC.setRecordingDuration();
*/
setRecordingDuration: function(milliseconds, callback) {
if (typeof milliseconds === 'undefined') {
Expand Down Expand Up @@ -350,7 +350,7 @@ function RecordRTC(mediaStream, config) {
},

/**
* This method returns DataURL. It takes single "callback" argument.
* This method returns the DataURL. It takes a single "callback" argument.
* @param {function} callback - DataURL is passed back over this callback.
* @method
* @memberof RecordRTC
Expand All @@ -365,7 +365,7 @@ function RecordRTC(mediaStream, config) {
getDataURL: getDataURL,

/**
* This method returns Virutal/Blob URL. It doesn't take any argument.
* This method returns the Virutal/Blob URL. It doesn't take any arguments.
* @method
* @memberof RecordRTC
* @instance
Expand All @@ -383,7 +383,7 @@ function RecordRTC(mediaStream, config) {
},

/**
* This method saves blob/file into disk (by inovking save-as dialog). It takes single (optional) argument i.e. FileName
* This method saves the blob/file to disk (by invoking save-as dialog). It takes a single (optional) argument i.e. FileName
* @method
* @memberof RecordRTC
* @instance
Expand All @@ -401,7 +401,7 @@ function RecordRTC(mediaStream, config) {
},

/**
* This method gets blob from indexed-DB storage. It takes single "callback" argument.
* This method gets a blob from indexed-DB storage. It takes a single "callback" argument.
* @method
* @memberof RecordRTC
* @instance
Expand All @@ -419,7 +419,7 @@ function RecordRTC(mediaStream, config) {
},

/**
* This method appends prepends array of webp images to the recorded video-blob. It takes an "array" object.
* This method appends an array of webp images to the recorded video-blob. It takes an "array" object.
* @type {Array.<Array>}
* @param {Array} arrayOfWebPImages - Array of webp images.
* @method
Expand Down Expand Up @@ -514,7 +514,7 @@ function RecordRTC(mediaStream, config) {
return returnObject;
}

// if someone wanna use RecordRTC with "new" keyword.
// if someone wants to use RecordRTC with the "new" keyword.
for (var prop in returnObject) {
this[prop] = returnObject[prop];
}
Expand Down Expand Up @@ -773,7 +773,7 @@ function GetRecorderType(mediaStream, config) {
// MRecordRTC.js

/**
* MRecordRTC runs top over {@link RecordRTC} to bring multiple recordings in single place, by providing simple API.
* MRecordRTC runs on top of {@link RecordRTC} to bring multiple recordings in a single place, by providing simple API.
* @summary MRecordRTC stands for "Multiple-RecordRTC".
* @license {@link https://github.com/muaz-khan/RecordRTC#license|MIT}
* @author {@link http://www.MuazKhan.com|Muaz Khan}
Expand Down Expand Up @@ -816,7 +816,7 @@ function MRecordRTC(mediaStream) {
};

/**
* This property can be used to set recording type e.g. audio, or video, or gif, or canvas.
* This property can be used to set the recording type e.g. audio, or video, or gif, or canvas.
* @property {object} mediaType - {audio: true, video: true, gif: true}
* @memberof MRecordRTC
* @example
Expand Down Expand Up @@ -849,12 +849,12 @@ function MRecordRTC(mediaStream) {
};

if (typeof mediaType.audio !== 'function' && isMediaRecorderCompatible() && mediaStream.getAudioTracks && !mediaStream.getAudioTracks().length) {
// Firefox is supporting both audio/video in single blob
// Firefox supports both audio/video in single blob
mediaType.audio = false;
}

if (typeof mediaType.video !== 'function' && isMediaRecorderCompatible() && mediaStream.getVideoTracks && !mediaStream.getVideoTracks().length) {
// Firefox is supporting both audio/video in single blob
// Firefox supports both audio/video in single blob
mediaType.video = false;
}

Expand Down Expand Up @@ -899,7 +899,7 @@ function MRecordRTC(mediaStream) {
newStream.addTrack(videoTrack);

if (recorderType && recorderType === WhammyRecorder) {
// Firefox is NOT supporting webp-encoding yet
// Firefox does NOT support webp-encoding yet
recorderType = MediaStreamRecorder;
}
} else {
Expand Down Expand Up @@ -956,8 +956,8 @@ function MRecordRTC(mediaStream) {
};

/**
* This method stop recording.
* @param {function} callback - Callback function is invoked when all encoders finish their jobs.
* This method stops recording.
* @param {function} callback - Callback function is invoked when all encoders finished their jobs.
* @method
* @memberof MRecordRTC
* @example
Expand Down Expand Up @@ -989,9 +989,51 @@ function MRecordRTC(mediaStream) {
}
};

/**
* This method pauses recording.
* @method
* @memberof MRecordRTC
* @example
* recorder.pauseRecording();
*/
this.pauseRecording = function() {
if (this.audioRecorder) {
this.audioRecorder.pauseRecording();
}

if (this.videoRecorder) {
this.videoRecorder.pauseRecording();
}

if (this.gifRecorder) {
this.gifRecorder.pauseRecording();
}
};

/**
* This method resumes recording.
* @method
* @memberof MRecordRTC
* @example
* recorder.resumeRecording();
*/
this.resumeRecording = function() {
if (this.audioRecorder) {
this.audioRecorder.resumeRecording();
}

if (this.videoRecorder) {
this.videoRecorder.resumeRecording();
}

if (this.gifRecorder) {
this.gifRecorder.resumeRecording();
}
};

/**
* This method can be used to manually get all recorded blobs.
* @param {function} callback - All recorded blobs are passed back to "callback" function.
* @param {function} callback - All recorded blobs are passed back to the "callback" function.
* @method
* @memberof MRecordRTC
* @example
Expand Down Expand Up @@ -1028,7 +1070,7 @@ function MRecordRTC(mediaStream) {

/**
* This method can be used to manually get all recorded blobs' DataURLs.
* @param {function} callback - All recorded blobs' DataURLs are passed back to "callback" function.
* @param {function} callback - All recorded blobs' DataURLs are passed back to the "callback" function.
* @method
* @memberof MRecordRTC
* @example
Expand Down Expand Up @@ -1107,7 +1149,7 @@ function MRecordRTC(mediaStream) {
};

/**
* This method can be used to invoke save-as dialog for all recorded blobs.
* This method can be used to invoke a save-as dialog for all recorded blobs.
* @param {object} args - {audio: 'audio-name', video: 'video-name', gif: 'gif-name'}
* @method
* @memberof MRecordRTC
Expand Down
6 changes: 3 additions & 3 deletions RecordRTC.min.js

Large diffs are not rendered by default.

62 changes: 52 additions & 10 deletions dev/MRecordRTC.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// MRecordRTC.js

/**
* MRecordRTC runs top over {@link RecordRTC} to bring multiple recordings in single place, by providing simple API.
* MRecordRTC runs on top of {@link RecordRTC} to bring multiple recordings in a single place, by providing simple API.
* @summary MRecordRTC stands for "Multiple-RecordRTC".
* @license {@link https://github.com/muaz-khan/RecordRTC#license|MIT}
* @author {@link http://www.MuazKhan.com|Muaz Khan}
Expand Down Expand Up @@ -45,7 +45,7 @@ function MRecordRTC(mediaStream) {
};

/**
* This property can be used to set recording type e.g. audio, or video, or gif, or canvas.
* This property can be used to set the recording type e.g. audio, or video, or gif, or canvas.
* @property {object} mediaType - {audio: true, video: true, gif: true}
* @memberof MRecordRTC
* @example
Expand Down Expand Up @@ -78,12 +78,12 @@ function MRecordRTC(mediaStream) {
};

if (typeof mediaType.audio !== 'function' && isMediaRecorderCompatible() && mediaStream.getAudioTracks && !mediaStream.getAudioTracks().length) {
// Firefox is supporting both audio/video in single blob
// Firefox supports both audio/video in single blob
mediaType.audio = false;
}

if (typeof mediaType.video !== 'function' && isMediaRecorderCompatible() && mediaStream.getVideoTracks && !mediaStream.getVideoTracks().length) {
// Firefox is supporting both audio/video in single blob
// Firefox supports both audio/video in single blob
mediaType.video = false;
}

Expand Down Expand Up @@ -128,7 +128,7 @@ function MRecordRTC(mediaStream) {
newStream.addTrack(videoTrack);

if (recorderType && recorderType === WhammyRecorder) {
// Firefox is NOT supporting webp-encoding yet
// Firefox does NOT support webp-encoding yet
recorderType = MediaStreamRecorder;
}
} else {
Expand Down Expand Up @@ -185,8 +185,8 @@ function MRecordRTC(mediaStream) {
};

/**
* This method stop recording.
* @param {function} callback - Callback function is invoked when all encoders finish their jobs.
* This method stops recording.
* @param {function} callback - Callback function is invoked when all encoders finished their jobs.
* @method
* @memberof MRecordRTC
* @example
Expand Down Expand Up @@ -218,9 +218,51 @@ function MRecordRTC(mediaStream) {
}
};

/**
* This method pauses recording.
* @method
* @memberof MRecordRTC
* @example
* recorder.pauseRecording();
*/
this.pauseRecording = function() {
if (this.audioRecorder) {
this.audioRecorder.pauseRecording();
}

if (this.videoRecorder) {
this.videoRecorder.pauseRecording();
}

if (this.gifRecorder) {
this.gifRecorder.pauseRecording();
}
};

/**
* This method resumes recording.
* @method
* @memberof MRecordRTC
* @example
* recorder.resumeRecording();
*/
this.resumeRecording = function() {
if (this.audioRecorder) {
this.audioRecorder.resumeRecording();
}

if (this.videoRecorder) {
this.videoRecorder.resumeRecording();
}

if (this.gifRecorder) {
this.gifRecorder.resumeRecording();
}
};

/**
* This method can be used to manually get all recorded blobs.
* @param {function} callback - All recorded blobs are passed back to "callback" function.
* @param {function} callback - All recorded blobs are passed back to the "callback" function.
* @method
* @memberof MRecordRTC
* @example
Expand Down Expand Up @@ -257,7 +299,7 @@ function MRecordRTC(mediaStream) {

/**
* This method can be used to manually get all recorded blobs' DataURLs.
* @param {function} callback - All recorded blobs' DataURLs are passed back to "callback" function.
* @param {function} callback - All recorded blobs' DataURLs are passed back to the "callback" function.
* @method
* @memberof MRecordRTC
* @example
Expand Down Expand Up @@ -336,7 +378,7 @@ function MRecordRTC(mediaStream) {
};

/**
* This method can be used to invoke save-as dialog for all recorded blobs.
* This method can be used to invoke a save-as dialog for all recorded blobs.
* @param {object} args - {audio: 'audio-name', video: 'video-name', gif: 'gif-name'}
* @method
* @memberof MRecordRTC
Expand Down
Loading

0 comments on commit 56a7afb

Please sign in to comment.