Skip to content

Commit

Permalink
Added msr@1.3.2 Fixed tinny bugs in MediaRecorderWrapper.js
Browse files Browse the repository at this point in the history
  • Loading branch information
muaz-khan committed May 15, 2016
1 parent ce029d2 commit 62ab10e
Show file tree
Hide file tree
Showing 11 changed files with 179 additions and 28 deletions.
22 changes: 17 additions & 5 deletions AudioStreamRecorder/MediaRecorderWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function MediaRecorderWrapper(mediaStream) {
* @example
* recorder.record();
*/
this.start = function(timeSlice) {
this.start = function(timeSlice, __disableLogs) {
if (!self.mimeType) {
self.mimeType = 'video/webm';
}
Expand All @@ -46,12 +46,13 @@ function MediaRecorderWrapper(mediaStream) {
}

self.blob = null;
self.dontFireOnDataAvailableEvent = false;

var recorderHints = {
mimeType: self.mimeType
};

if (!self.disableLogs) {
if (!self.disableLogs && !__disableLogs) {
console.log('Passing following params over MediaRecorder API.', recorderHints);
}

Expand Down Expand Up @@ -99,8 +100,12 @@ function MediaRecorderWrapper(mediaStream) {

self.ondataavailable(blob);

self.dontFireOnDataAvailableEvent = true;
mediaRecorder.stop();
mediaRecorder = null;

// record next interval
self.start(timeSlice);
self.start(timeSlice, '__disableLogs');
};

mediaRecorder.onerror = function(error) {
Expand Down Expand Up @@ -146,7 +151,7 @@ function MediaRecorderWrapper(mediaStream) {
if (mediaRecorder.state === 'recording') {
// "stop" method auto invokes "requestData"!
mediaRecorder.requestData();
mediaRecorder.stop();
// mediaRecorder.stop();
}
}, timeSlice);

Expand Down Expand Up @@ -176,7 +181,14 @@ function MediaRecorderWrapper(mediaStream) {
if (mediaRecorder.state === 'recording') {
// "stop" method auto invokes "requestData"!
mediaRecorder.requestData();
mediaRecorder.stop();

setTimeout(function() {
self.dontFireOnDataAvailableEvent = true;
if (mediaRecorder.state === 'recording') {
mediaRecorder.stop();
}
mediaRecorder = null;
}, 2000);
}
};

Expand Down
1 change: 1 addition & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ module.exports = function(grunt) {
'VideoStreamRecorder/WhammyRecorderHelper.js',
'VideoStreamRecorder/GifRecorder.js',
'VideoStreamRecorder/lib/whammy.js',
'common/ConcatenateBlobs.js',
'common/amd.js'
],
dest: 'MediaStreamRecorder.js'
Expand Down
93 changes: 83 additions & 10 deletions MediaStreamRecorder.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Last time updated: 2016-05-05 6:31:59 AM UTC
// Last time updated: 2016-05-15 5:22:54 AM UTC

// links:
// Open-Sourced: https://github.com/streamproc/MediaStreamRecorder
Expand Down Expand Up @@ -106,11 +106,9 @@ function MediaStreamRecorder(mediaStream) {
return;
}

var bigBlob = new Blob(mediaRecorder.blobs, {
type: mediaRecorder.blobs[0].type || this.mimeType
ConcatenateBlobs(mediaRecorder.blobs, mediaRecorder.blobs[0].type, function(concatenatedBlob) {
invokeSaveAsDialog(concatenatedBlob);
});

invokeSaveAsDialog(bigBlob);
return;
}
invokeSaveAsDialog(file, fileName);
Expand Down Expand Up @@ -616,7 +614,7 @@ function MediaRecorderWrapper(mediaStream) {
* @example
* recorder.record();
*/
this.start = function(timeSlice) {
this.start = function(timeSlice, __disableLogs) {
if (!self.mimeType) {
self.mimeType = 'video/webm';
}
Expand All @@ -640,12 +638,13 @@ function MediaRecorderWrapper(mediaStream) {
}

self.blob = null;
self.dontFireOnDataAvailableEvent = false;

var recorderHints = {
mimeType: self.mimeType
};

if (!self.disableLogs) {
if (!self.disableLogs && !__disableLogs) {
console.log('Passing following params over MediaRecorder API.', recorderHints);
}

Expand Down Expand Up @@ -693,8 +692,12 @@ function MediaRecorderWrapper(mediaStream) {

self.ondataavailable(blob);

self.dontFireOnDataAvailableEvent = true;
mediaRecorder.stop();
mediaRecorder = null;

// record next interval
self.start(timeSlice);
self.start(timeSlice, '__disableLogs');
};

mediaRecorder.onerror = function(error) {
Expand Down Expand Up @@ -740,7 +743,7 @@ function MediaRecorderWrapper(mediaStream) {
if (mediaRecorder.state === 'recording') {
// "stop" method auto invokes "requestData"!
mediaRecorder.requestData();
mediaRecorder.stop();
// mediaRecorder.stop();
}
}, timeSlice);

Expand Down Expand Up @@ -770,7 +773,14 @@ function MediaRecorderWrapper(mediaStream) {
if (mediaRecorder.state === 'recording') {
// "stop" method auto invokes "requestData"!
mediaRecorder.requestData();
mediaRecorder.stop();

setTimeout(function() {
self.dontFireOnDataAvailableEvent = true;
if (mediaRecorder.state === 'recording') {
mediaRecorder.stop();
}
mediaRecorder = null;
}, 2000);
}
};

Expand Down Expand Up @@ -2113,6 +2123,69 @@ if (typeof MediaStreamRecorder !== 'undefined') {
MediaStreamRecorder.Whammy = Whammy;
}

// Last time updated at Nov 18, 2014, 08:32:23

// Latest file can be found here: https://cdn.webrtc-experiment.com/ConcatenateBlobs.js

// Muaz Khan - www.MuazKhan.com
// MIT License - www.WebRTC-Experiment.com/licence
// Source Code - https://github.com/muaz-khan/ConcatenateBlobs
// Demo - https://www.WebRTC-Experiment.com/ConcatenateBlobs/

// ___________________
// ConcatenateBlobs.js

// Simply pass array of blobs.
// This javascript library will concatenate all blobs in single "Blob" object.

(function() {
window.ConcatenateBlobs = function(blobs, type, callback) {
var buffers = [];

var index = 0;

function readAsArrayBuffer() {
if (!blobs[index]) {
return concatenateBuffers();
}
var reader = new FileReader();
reader.onload = function(event) {
buffers.push(event.target.result);
index++;
readAsArrayBuffer();
};
reader.readAsArrayBuffer(blobs[index]);
}

readAsArrayBuffer();

function concatenateBuffers() {
var byteLength = 0;
buffers.forEach(function(buffer) {
byteLength += buffer.byteLength;
});

var tmp = new Uint16Array(byteLength);
var lastOffset = 0;
buffers.forEach(function(buffer) {
// BYTES_PER_ELEMENT == 2 for Uint16Array
var reusableByteLength = buffer.byteLength;
if (reusableByteLength % 2 != 0) {
buffer = buffer.slice(0, reusableByteLength - 1)
}
tmp.set(new Uint16Array(buffer), lastOffset);
lastOffset += reusableByteLength;
});

var blob = new Blob([tmp.buffer], {
type: type
});

callback(blob);
}
};
})();

// https://github.com/streamproc/MediaStreamRecorder/issues/42
if (typeof module !== 'undefined' /* && !!module.exports*/ ) {
module.exports = MediaStreamRecorder;
Expand Down
5 changes: 3 additions & 2 deletions MediaStreamRecorder.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Then link single/standalone "MediaStreamRecorder.js" file:
<script src="https://cdn.webrtc-experiment.com/MediaStreamRecorder.js"> </script>

<!-- or link specific release -->
<script src="https://github.com/streamproc/MediaStreamRecorder/releases/download/1.3.1/MediaStreamRecorder.js"></script>
<script src="https://github.com/streamproc/MediaStreamRecorder/releases/download/1.3.2/MediaStreamRecorder.js"></script>
```

## Record audio+video
Expand Down
4 changes: 2 additions & 2 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "msr",
"version": "1.3.1",
"version": "1.3.2",
"authors": [
{
"name": "Muaz Khan",
Expand Down Expand Up @@ -62,7 +62,7 @@
"grunt-contrib-concat": "0.5.1",
"grunt-contrib-csslint": "0.4.0",
"grunt-contrib-uglify": "0.9.1",
"grunt-htmlhint": "0.4.1",
"grunt-htmlhint": "0.9.13",
"grunt-jsbeautifier": "0.2.10",
"grunt-bump": "0.3.1"
}
Expand Down
62 changes: 62 additions & 0 deletions common/ConcatenateBlobs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Last time updated at Nov 18, 2014, 08:32:23

// Latest file can be found here: https://cdn.webrtc-experiment.com/ConcatenateBlobs.js

// Muaz Khan - www.MuazKhan.com
// MIT License - www.WebRTC-Experiment.com/licence
// Source Code - https://github.com/muaz-khan/ConcatenateBlobs
// Demo - https://www.WebRTC-Experiment.com/ConcatenateBlobs/

// ___________________
// ConcatenateBlobs.js

// Simply pass array of blobs.
// This javascript library will concatenate all blobs in single "Blob" object.

(function() {
window.ConcatenateBlobs = function(blobs, type, callback) {
var buffers = [];

var index = 0;

function readAsArrayBuffer() {
if (!blobs[index]) {
return concatenateBuffers();
}
var reader = new FileReader();
reader.onload = function(event) {
buffers.push(event.target.result);
index++;
readAsArrayBuffer();
};
reader.readAsArrayBuffer(blobs[index]);
}

readAsArrayBuffer();

function concatenateBuffers() {
var byteLength = 0;
buffers.forEach(function(buffer) {
byteLength += buffer.byteLength;
});

var tmp = new Uint16Array(byteLength);
var lastOffset = 0;
buffers.forEach(function(buffer) {
// BYTES_PER_ELEMENT == 2 for Uint16Array
var reusableByteLength = buffer.byteLength;
if (reusableByteLength % 2 != 0) {
buffer = buffer.slice(0, reusableByteLength - 1)
}
tmp.set(new Uint16Array(buffer), lastOffset);
lastOffset += reusableByteLength;
});

var blob = new Blob([tmp.buffer], {
type: type
});

callback(blob);
}
};
})();
6 changes: 2 additions & 4 deletions common/MediaStreamRecorder.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,9 @@ function MediaStreamRecorder(mediaStream) {
return;
}

var bigBlob = new Blob(mediaRecorder.blobs, {
type: mediaRecorder.blobs[0].type || this.mimeType
ConcatenateBlobs(mediaRecorder.blobs, mediaRecorder.blobs[0].type, function(concatenatedBlob) {
invokeSaveAsDialog(concatenatedBlob);
});

invokeSaveAsDialog(bigBlob);
return;
}
invokeSaveAsDialog(file, fileName);
Expand Down
2 changes: 2 additions & 0 deletions demos/audio-recorder.html
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ <h1>
document.querySelector('#save-recording').onclick = function() {
this.disabled = true;
mediaRecorder.save();

// alert('Drop WebM file on Chrome or Firefox. Both can play entire file. VLC player or other players may not work.');
};

var mediaRecorder;
Expand Down
6 changes: 4 additions & 2 deletions demos/video-recorder.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
<article>
<header style="text-align: center;">
<h1>
<a href="https://www.webrtc-experiment.com/">WebRTC</a> Video Recording using <a href="https://github.com/streamproc/MediaStreamRecorder" target="_blank">MediaStreamRecorder</a>
</h1>
<a href="https://www.webrtc-experiment.com/">WebRTC</a> Video Recording using <a href="https://github.com/streamproc/MediaStreamRecorder" target="_blank">MediaStreamRecorder</a>
</h1>
<p>
<a href="https://www.webrtc-experiment.com/">HOME</a>
<span> &copy; </span>
Expand Down Expand Up @@ -117,6 +117,8 @@ <h1>
document.querySelector('#save-recording').onclick = function() {
this.disabled = true;
mediaRecorder.save();

// alert('Drop WebM file on Chrome or Firefox. Both can play entire file. VLC player or other players may not work.');
};

var mediaRecorder;
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "msr",
"preferGlobal": false,
"version": "1.3.1",
"version": "1.3.2",
"author": {
"name": "Muaz Khan",
"email": "muazkh@gmail.com",
Expand Down Expand Up @@ -68,7 +68,7 @@
"grunt-contrib-concat": "0.5.1",
"grunt-contrib-csslint": "0.4.0",
"grunt-contrib-uglify": "0.9.1",
"grunt-htmlhint": "0.4.1",
"grunt-htmlhint": "0.9.13",
"grunt-jsbeautifier": "0.2.10",
"grunt-bump": "0.3.1"
}
Expand Down

0 comments on commit 62ab10e

Please sign in to comment.