54 lines
1.2 KiB
JavaScript
54 lines
1.2 KiB
JavaScript
|
|
// ======================
|
||
|
|
// StereoAudioRecorder.js
|
||
|
|
|
||
|
|
function StereoAudioRecorder(mediaStream) {
|
||
|
|
// void start(optional long timeSlice)
|
||
|
|
// timestamp to fire "ondataavailable"
|
||
|
|
this.start = function(timeSlice) {
|
||
|
|
timeSlice = timeSlice || 1000;
|
||
|
|
|
||
|
|
mediaRecorder = new StereoAudioRecorderHelper(mediaStream, this);
|
||
|
|
|
||
|
|
mediaRecorder.record();
|
||
|
|
|
||
|
|
timeout = setInterval(function() {
|
||
|
|
mediaRecorder.requestData();
|
||
|
|
}, timeSlice);
|
||
|
|
};
|
||
|
|
|
||
|
|
this.stop = function() {
|
||
|
|
if (mediaRecorder) {
|
||
|
|
mediaRecorder.stop();
|
||
|
|
clearTimeout(timeout);
|
||
|
|
this.onstop();
|
||
|
|
}
|
||
|
|
};
|
||
|
|
|
||
|
|
this.pause = function() {
|
||
|
|
if (!mediaRecorder) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
mediaRecorder.pause();
|
||
|
|
};
|
||
|
|
|
||
|
|
this.resume = function() {
|
||
|
|
if (!mediaRecorder) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
mediaRecorder.resume();
|
||
|
|
};
|
||
|
|
|
||
|
|
this.ondataavailable = function() {};
|
||
|
|
this.onstop = function() {};
|
||
|
|
|
||
|
|
// Reference to "StereoAudioRecorder" object
|
||
|
|
var mediaRecorder;
|
||
|
|
var timeout;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (typeof MediaStreamRecorder !== 'undefined') {
|
||
|
|
MediaStreamRecorder.StereoAudioRecorder = StereoAudioRecorder;
|
||
|
|
}
|