Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added ability to sync video with capture #60

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 53 additions & 30 deletions src/CCapture.js
Original file line number Diff line number Diff line change
Expand Up @@ -707,22 +707,28 @@ function CCapture( settings ) {
return _performanceTime;
};

function hookCurrentTime() { 
if( !this._hooked ) {
this._hooked = true;
this._hookedTime = this.currentTime || 0;
this.pause();
media.push( this );
}
return this._hookedTime + _settings.startTime;
};

try {
Object.defineProperty( HTMLVideoElement.prototype, 'currentTime', { get: hookCurrentTime } )
Object.defineProperty( HTMLAudioElement.prototype, 'currentTime', { get: hookCurrentTime } )
} catch (err) {
_log(err);
}
if (_settings.syncVideo) {
_settings.syncVideo.pause();
_settings.syncVideo.addEventListener('seeked', _callCallbacks);
}
else {
function hookCurrentTime() { 
if( !this._hooked ) {
this._hooked = true;
this._hookedTime = this.currentTime || 0;
this.pause();
media.push( this );
}
return this._hookedTime + _settings.startTime;
};

try {
Object.defineProperty( HTMLVideoElement.prototype, 'currentTime', { get: hookCurrentTime } )
Object.defineProperty( HTMLAudioElement.prototype, 'currentTime', { get: hookCurrentTime } )
} catch (err) {
_log(err);
}
}

}

Expand Down Expand Up @@ -757,6 +763,12 @@ function CCapture( settings ) {
window.Date.prototype.getTime = _oldGetTime;
window.Date.now = _oldNow;
window.performance.now = _oldPerformanceNow;

if (_settings.syncVideo) {
_settings.syncVideo.removeEventListener('seeked', _callCallbacks);
_settings.syncVideo.play();
_callCallbacks();
}
}

function _updateTime() {
Expand Down Expand Up @@ -847,21 +859,8 @@ function CCapture( settings ) {
}

}

function _process() {

var step = 1000 / _settings.framerate;
var dt = ( _frameCount + _intermediateFrameCount / _settings.motionBlurFrames ) * step;

_time = _startTime + dt;
_performanceTime = _performanceStartTime + dt;

media.forEach( function( v ) {
v._hookedTime = dt / 1000;
} );

_updateTime();
_log( 'Frame: ' + _frameCount + ' ' + _intermediateFrameCount );
function _callCallbacks() {

for( var j = 0; j < _timeouts.length; j++ ) {
if( _time >= _timeouts[ j ].triggerTime ) {
Expand All @@ -886,6 +885,30 @@ function CCapture( settings ) {
} );
_requestAnimationFrameCallbacks = [];

}

function _process() {

var step = 1000 / _settings.framerate;
var dt = ( _frameCount + _intermediateFrameCount / _settings.motionBlurFrames ) * step;

_time = _startTime + dt;
_performanceTime = _performanceStartTime + dt;

media.forEach( function( v ) {
v._hookedTime = dt / 1000;
} );

_updateTime();
_log( 'Frame: ' + _frameCount + ' ' + _intermediateFrameCount );

if (_settings.syncVideo) {
_settings.syncVideo.currentTime += step / 1000;
}
else {
_callCallbacks();
}

}

function _save( callback ) {
Expand Down