},
exec: function ( time, fn ) {
-
- !fn && ( fn = Popcorn.nop );
-
- var self = this,
- guid = Popcorn.guid( "execCallback" ),
- callback = function execCallback( event ) {
- if ( Math.round( this.currentTime() ) === time && !callback.fired ) {
-
- callback.fired = true;
-
- fn.call(self, event);
-
- // Enforce a once per second execution
- setTimeout(function() {
-
- callback.fired = false;
-
- }, 1000 );
- }
- };
-
- callback.fired = false;
- callback.name = guid;
-
- this.listen("timeupdate", callback);
+ // creating a one second track event with an empty end
+ Popcorn.addTrackEvent( this, {
+ start: time,
+ end: time + 1,
+ _running: false,
+ _natives: {
+ start: fn,
+ type: "exec"
+ }
+ });
return this;
}
Popcorn.addTrackEvent = function( obj, track ) {
-
+
if ( track._natives ) {
// supports user defined track event id
track._id = !track.id ? Popcorn.guid( track._natives.type ) : track.id;
hasLooped = false,
loop = 0;
- expect(expects);
+ expect( expects + 1 );
function plus(){
if ( ++count == expects ) {
- popped.unlisten( "timeupdate", "execCallback" );
-
-
- start();
+ setTimeout( function() {
+
+ equals( loop, expects, "exec callback repeat check, only called twice" );
+ Popcorn.removePlugin( popped, "exec" );
+ start();
+
+ }, 1000 );
}
}
stop( 10000 );
popped.exec( 4, function () {
- ok(true, "exec callback fired " + loop++ );
+ ok( loop < 2, "exec callback fired " + ++loop );
plus();
if ( !hasLooped ) {