Skip to content

Commit

Permalink
[#888] no longer polling readyState
Browse files Browse the repository at this point in the history
  • Loading branch information
ScottDowne committed Jan 5, 2012
1 parent d1053a9 commit fda3bab
Showing 1 changed file with 44 additions and 34 deletions.
78 changes: 44 additions & 34 deletions popcorn.js
Expand Up @@ -243,58 +243,68 @@
}
};

// Wrap true ready check
// function to fire when video is ready
var isReady = function( that ) {

var duration, videoDurationPlus;

if ( that.media.readyState >= 2 ) {
// Adding padding to the front and end of the arrays
// this is so we do not fall off either end
// Adding padding to the front and end of the arrays
// this is so we do not fall off either end
duration = that.media.duration;

duration = that.media.duration;
// Check for no duration info (NaN)
videoDurationPlus = duration != duration ? Number.MAX_VALUE : duration + 1;
// Check for no duration info (NaN)
videoDurationPlus = duration != duration ? Number.MAX_VALUE : duration + 1;

Popcorn.addTrackEvent( that, {
start: videoDurationPlus,
end: videoDurationPlus
});
Popcorn.addTrackEvent( that, {
start: videoDurationPlus,
end: videoDurationPlus
});

if ( that.options.frameAnimation ) {
// if Popcorn is created with frameAnimation option set to true,
// requestAnimFrame is used instead of "timeupdate" media event.
// This is for greater frame time accuracy, theoretically up to
// 60 frames per second as opposed to ~4 ( ~every 15-250ms)
that.data.timeUpdate = function () {
if ( that.options.frameAnimation ) {
// if Popcorn is created with frameAnimation option set to true,
// requestAnimFrame is used instead of "timeupdate" media event.
// This is for greater frame time accuracy, theoretically up to
// 60 frames per second as opposed to ~4 ( ~every 15-250ms)
that.data.timeUpdate = function () {

Popcorn.timeUpdate( that, {} );
Popcorn.timeUpdate( that, {} );

that.trigger( "timeupdate" );

!that.isDestroyed && requestAnimFrame( that.data.timeUpdate );
};
that.trigger( "timeupdate" );

!that.isDestroyed && requestAnimFrame( that.data.timeUpdate );
};

} else {
!that.isDestroyed && requestAnimFrame( that.data.timeUpdate );

that.data.timeUpdate = function( event ) {
Popcorn.timeUpdate( that, event );
};
} else {

if ( !that.isDestroyed ) {
that.media.addEventListener( "timeupdate", that.data.timeUpdate, false );
}
that.data.timeUpdate = function( event ) {
Popcorn.timeUpdate( that, event );
};

if ( !that.isDestroyed ) {
that.media.addEventListener( "timeupdate", that.data.timeUpdate, false );
}
} else {
global.setTimeout(function() {
isReady( that );
}, 1 );
}
};

isReady( this );
if ( this.media.readyState >= 2 ) {

isReady( this );
} else {

this.media.addEventListener( "loadeddata", (function( instance ) {

var listener = function() {

instance.media.removeEventListener( "loadeddata", listener, false );

isReady( instance );
};

return listener;
}( this )), false );
}

return this;
}
Expand Down

0 comments on commit fda3bab

Please sign in to comment.