67 lines
1.4 KiB
JavaScript
67 lines
1.4 KiB
JavaScript
|
|
// ===================
|
||
|
|
// WhammyRecorder.js
|
||
|
|
|
||
|
|
function WhammyRecorder(mediaStream) {
|
||
|
|
// void start(optional long timeSlice)
|
||
|
|
// timestamp to fire "ondataavailable"
|
||
|
|
this.start = function(timeSlice) {
|
||
|
|
timeSlice = timeSlice || 1000;
|
||
|
|
|
||
|
|
mediaRecorder = new WhammyRecorderHelper(mediaStream, this);
|
||
|
|
|
||
|
|
for (var prop in this) {
|
||
|
|
if (typeof this[prop] !== 'function') {
|
||
|
|
mediaRecorder[prop] = this[prop];
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
mediaRecorder.record();
|
||
|
|
|
||
|
|
timeout = setInterval(function() {
|
||
|
|
mediaRecorder.requestData();
|
||
|
|
}, timeSlice);
|
||
|
|
};
|
||
|
|
|
||
|
|
this.stop = function() {
|
||
|
|
if (mediaRecorder) {
|
||
|
|
mediaRecorder.stop();
|
||
|
|
clearTimeout(timeout);
|
||
|
|
this.onstop();
|
||
|
|
}
|
||
|
|
};
|
||
|
|
|
||
|
|
this.onstop = function() {};
|
||
|
|
|
||
|
|
this.clearOldRecordedFrames = function() {
|
||
|
|
if (mediaRecorder) {
|
||
|
|
mediaRecorder.clearOldRecordedFrames();
|
||
|
|
}
|
||
|
|
};
|
||
|
|
|
||
|
|
this.pause = function() {
|
||
|
|
if (!mediaRecorder) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
mediaRecorder.pause();
|
||
|
|
};
|
||
|
|
|
||
|
|
this.resume = function() {
|
||
|
|
if (!mediaRecorder) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
mediaRecorder.resume();
|
||
|
|
};
|
||
|
|
|
||
|
|
this.ondataavailable = function() {};
|
||
|
|
|
||
|
|
// Reference to "WhammyRecorder" object
|
||
|
|
var mediaRecorder;
|
||
|
|
var timeout;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (typeof MediaStreamRecorder !== 'undefined') {
|
||
|
|
MediaStreamRecorder.WhammyRecorder = WhammyRecorder;
|
||
|
|
}
|