Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Implements a common instance.data.timeUpdate function across frame an…
Browse files Browse the repository at this point in the history
…imating and non-frame animating Popcorn instances [#807]
  • Loading branch information
Christopher De Cairos committed Nov 1, 2011
2 parents 439283a + 160c753 commit b221795
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 8 deletions.
17 changes: 10 additions & 7 deletions popcorn.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,9 @@

this.data = {

// Executed by either timeupdate event or in rAF loop
timeUpdate: Popcorn.nop,

// Allows disabling a plugin per instance
disabled: [],

Expand Down Expand Up @@ -243,7 +246,7 @@
// Wrap true ready check
var isReady = function( that ) {

var duration, videoDurationPlus, animate;
var duration, videoDurationPlus;

if ( that.media.readyState >= 2 ) {
// Adding padding to the front and end of the arrays
Expand All @@ -263,25 +266,25 @@
// 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)
animate = function () {
that.data.timeUpdate = function () {

Popcorn.timeUpdate( that, {} );

that.trigger( "timeupdate" );

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

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

} else {

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

if ( !that.isDestroyed ) {
that.media.addEventListener( "timeupdate", that.data.timeUpdateFunction, false );
that.media.addEventListener( "timeupdate", that.data.timeUpdate, false );
}
}
} else {
Expand Down Expand Up @@ -443,7 +446,7 @@
}

if ( !instance.isDestroyed ) {
instance.data.timeUpdateFunction && instance.media.removeEventListener( "timeupdate", instance.data.timeUpdateFunction, false );
instance.data.timeUpdate && instance.media.removeEventListener( "timeupdate", instance.data.timeUpdate, false );
instance.isDestroyed = true;
}
}
Expand Down
65 changes: 64 additions & 1 deletion test/popcorn.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,69 @@ test( "Object", function() {
});
});

test( "Instance", function() {

var a = Popcorn( "#video" ),
b = Popcorn( "#video", { frameAnimation: true });

expect( 36 );

ok( a.options, "instance a has options property" );
ok( b.options, "instance b has options property" );

ok( a.isDestroyed === false , "instance a has isDestroyed property" );
ok( b.isDestroyed === false, "instance b has isDestroyed property" );

ok( a.data, "instance a has data property" );
ok( b.data, "instance b has data property" );

ok( a.data.timeUpdate, "instance a has data.timeUpdate property" );
ok( b.data.timeUpdate, "instance b has data.timeUpdate property" );

ok( a.data.disabled, "instance a has data.disabled property" );
ok( b.data.disabled, "instance b has data.disabled property" );

ok( a.data.events, "instance a has data.events property" );
ok( b.data.events, "instance b has data.events property" );

ok( a.data.hooks, "instance a has data.hooks property" );
ok( b.data.hooks, "instance b has data.hooks property" );

ok( a.data.history, "instance a has data.history property" );
ok( b.data.history, "instance b has data.history property" );

ok( a.data.state, "instance a has data.state property" );
ok( b.data.state, "instance b has data.state property" );

ok( a.data.state.volume, "instance a has data.state.volume property" );
ok( b.data.state.volume, "instance b has data.state.volume property" );

ok( a.data.trackRefs, "instance a has data.trackRefs property" );
ok( b.data.trackRefs, "instance b has data.trackRefs property" );

ok( a.data.trackEvents, "instance a has data.trackEvents property" );
ok( b.data.trackEvents, "instance b has data.trackEvents property" );

ok( a.data.trackEvents.byStart, "instance a has data.trackEvents.byStart property" );
ok( b.data.trackEvents.byStart, "instance b has data.trackEvents.byStart property" );

ok( a.data.trackEvents.byEnd, "instance a has data.trackEvents.byEnd property" );
ok( b.data.trackEvents.byEnd, "instance b has data.trackEvents.byEnd property" );

ok( a.data.trackEvents.animating, "instance a has data.trackEvents.animating property" );
ok( b.data.trackEvents.animating, "instance b has data.trackEvents.animating property" );

ok( a.data.trackEvents.startIndex, "instance a has data.trackEvents.startIndex property" );
ok( b.data.trackEvents.startIndex, "instance b has data.trackEvents.startIndex property" );

ok( a.data.trackEvents.endIndex, "instance a has data.trackEvents.endIndex property" );
ok( b.data.trackEvents.endIndex, "instance b has data.trackEvents.endIndex property" );

ok( a.data.trackEvents.previousUpdateTime >= -1, "instance a has data.trackEvents.previousUpdateTime property" );
ok( b.data.trackEvents.previousUpdateTime >= -1, "instance b has data.trackEvents.previousUpdateTime property" );

});

module( "Popcorn Static" );

test( "Popcorn.[addTrackEvent | removeTrackEvent].ref()", function() {
Expand Down Expand Up @@ -1473,7 +1536,7 @@ test( "Manifest removal", function() {
equal( Popcorn.sizeOf( Popcorn.manifest ), 0, "Before creating new plugin" );

Popcorn.plugin( "tester", {

start: function() {},
end: function() {}
});
Expand Down

0 comments on commit b221795

Please sign in to comment.