Skip to content
This repository has been archived by the owner on May 18, 2021. It is now read-only.

Commit

Permalink
update dist 0.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuochun committed Aug 9, 2013
1 parent 8c7e88c commit 5201ef3
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 31 deletions.
82 changes: 56 additions & 26 deletions dist/RecordRTC-together.js
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,8 @@ function StereoAudioRecorder(mediaStream, root) {
enable: { video: true, audio: true },
canvas_width: 320,
canvas_height: 240,
video_fps: 10
video_fps: 10,
video_quality: 0.8
};

function RecordRTC(options) {
Expand All @@ -644,6 +645,9 @@ function StereoAudioRecorder(mediaStream, root) {
this.lastVideoFrame = null;
// audio
this.audioRecorder = null;
// recording flags
this.videoStarted = false;
this.audioStarted = false;
}

RecordRTC.prototype = {
Expand All @@ -659,6 +663,8 @@ function StereoAudioRecorder(mediaStream, root) {
this.stream = mediaStream;
// output to video elem
this.videoElem.src = URL.createObjectURL(mediaStream);
// init recording
this.init();
},
// draw video frame
drawVideoFrame: function(time) {
Expand All @@ -679,9 +685,13 @@ function StereoAudioRecorder(mediaStream, root) {

this.lastFrameTime = time;
},
// init video record
initVideo: function() {
console.log('init recording video frames');
},
// start video record
startVideo: function() {
console.log('started recording video frames');
console.log('start recording video frames');

// reset video blob
this.videoBlob = null;
Expand All @@ -706,14 +716,22 @@ function StereoAudioRecorder(mediaStream, root) {
this.videoElem.width = this.v_width;
this.videoElem.height = this.v_height;

this.whammy = new Whammy.Video(this.options.video_fps || defaults.video_fps, 0.6);
// whammy library to record canvas
this.whammy = new Whammy.Video(this.options.video_fps || defaults.video_fps,
this.options.video_quality || defaults.video_quality);

this.videoStarted = true;

this.lastVideoFrame = requestAnimationFrame(this.drawVideoFrame.bind(this));
},
// stop video record
stopVideo: function(callback) {
if (!this.videoStarted) { return ; }

console.log('stopped recording video frames');

this.videoStarted = false;

if (this.lastVideoFrame) {
cancelAnimationFrame(this.lastVideoFrame);
}
Expand All @@ -723,52 +741,54 @@ function StereoAudioRecorder(mediaStream, root) {
this.onVideoReady(this.whammy.compile());
}
},
// init audio record
initAudio: function() {
console.log('init recording audio frames');

var self = this,
onDataReady = {
ondataavailable: self.onAudioReady.bind(self)
};

this.audioRecorder = new StereoAudioRecorder(self.stream, onDataReady);
},
// start audio record
startAudio: function() {
console.log('started recording audio frames');
console.log('start recording audio frames');

// reset audio blob
this.audioBlob = null;

var self = this,
onDataReady = {
ondataavailable: self.onAudioReady.bind(self)
};
this.initAudio(); // do it again

this.audioRecorder = new StereoAudioRecorder(this.stream, onDataReady);
this.audioStarted = true;

this.audioRecorder.record();
},
// stop audio record
stopAudio: function(callback) {
if (!this.audioRecorder) { return ; }
if (!this.audioStarted) { return ; }

console.info('stopped recording audio frames');

this.audioStarted = false;

this.audioRecorder.stop();
},
// start record all
start: function() {
// init recorder
init: function() {
if (!this.videoElem) { throw "No Video Element Found!"; }
if (!this.stream) { throw "Media is not ready!"; }

if (this.options.enable) {
if (this.options.enable.audio) this.startAudio();
if (this.options.enable.video) this.startVideo();
} else if (defaults.enable) {
if (defaults.enable.audio) this.startAudio();
if (defaults.enable.video) this.startVideo();
}
batchActions(this.options, this, "init");
},
// start record all
start: function() {
batchActions(this.options, this, "start");
},
// stop record all
stop: function() {
if (this.options.enable) {
if (this.options.enable.video) this.stopVideo();
if (this.options.enable.audio) this.stopAudio();
} else if (defaults.enable) {
if (defaults.enable.video) this.stopVideo();
if (defaults.enable.audio) this.stopAudio();
}
batchActions(this.options, this, "stop");
},
// on video ready
onVideoReady: function(callback) {
Expand Down Expand Up @@ -808,6 +828,16 @@ function StereoAudioRecorder(mediaStream, root) {
}
};

function batchActions(options, self, action) {
if (options.enable) {
if (options.enable.audio) self[action + "Audio"]();
if (options.enable.video) self[action + "Video"]();
} else if (defaults.enable) {
if (defaults.enable.audio) self[action + "Audio"]();
if (defaults.enable.video) self[action + "Video"]();
}
}

function isFunction(f) {
return Object.prototype.toString.call(f) === "[object Function]";
}
Expand Down
Loading

0 comments on commit 5201ef3

Please sign in to comment.