Permalink
Browse files

Add timeUpdate() function [#659]

  • Loading branch information...
2 parents 9a0f923 + b0141ab commit c243c50fb5b40639d22a232ba44a93e719d338a7 @jbuck committed Aug 26, 2011
Showing with 105 additions and 94 deletions.
  1. +1 −1 plugins/subtitle/popcorn.subtitle.unit.js
  2. +104 −93 popcorn.js
@@ -118,7 +118,7 @@ test("Popcorn Subtitle Plugin", function () {
popped.exec( 8, function() {
popped.pause();
- popped2.currentTime( 8 );
+ popped2.currentTime( 8 ).play();
});
popped2.exec( 8, function() {
View
@@ -214,99 +214,7 @@
that.media.addEventListener( "timeupdate", function( event ) {
- var currentTime = this.currentTime,
- previousTime = that.data.trackEvents.previousUpdateTime,
- tracks = that.data.trackEvents,
- tracksByEnd = tracks.byEnd,
- tracksByStart = tracks.byStart;
-
- // Playbar advancing
- if ( previousTime < currentTime ) {
-
- while ( tracksByEnd[ tracks.endIndex ] && tracksByEnd[ tracks.endIndex ].end <= currentTime ) {
- // If plugin does not exist on this instance, remove it
- if ( !tracksByEnd[ tracks.endIndex ]._natives ||
- ( !!Popcorn.registryByName[ tracksByEnd[ tracks.endIndex ]._natives.type ] ||
- !!that[ tracksByEnd[ tracks.endIndex ]._natives.type ] ) ) {
-
- if ( tracksByEnd[ tracks.endIndex ]._running === true ) {
- tracksByEnd[ tracks.endIndex ]._running = false;
- tracksByEnd[ tracks.endIndex ]._natives.end.call( that, event, tracksByEnd[ tracks.endIndex ] );
- }
- tracks.endIndex++;
- } else {
- // remove track event
- Popcorn.removeTrackEvent( that, tracksByEnd[ tracks.endIndex ]._id );
- return;
- }
- }
-
- while ( tracksByStart[ tracks.startIndex ] && tracksByStart[ tracks.startIndex ].start <= currentTime ) {
- // If plugin does not exist on this instance, remove it
- if ( !tracksByStart[ tracks.startIndex ]._natives ||
- ( !!Popcorn.registryByName[ tracksByStart[ tracks.startIndex ]._natives.type ] ||
- !!that[ tracksByStart[ tracks.startIndex ]._natives.type ] ) ) {
-
- if ( tracksByStart[ tracks.startIndex ].end > currentTime &&
- tracksByStart[ tracks.startIndex ]._running === false &&
- that.data.disabled.indexOf( tracksByStart[ tracks.startIndex ]._natives.type ) === -1 ) {
-
- tracksByStart[ tracks.startIndex ]._running = true;
- tracksByStart[ tracks.startIndex ]._natives.start.call( that, event, tracksByStart[ tracks.startIndex ] );
- }
- tracks.startIndex++;
- } else {
- // remove track event
- Popcorn.removeTrackEvent( that, tracksByStart[ tracks.startIndex ]._id );
- return;
- }
- }
-
- // Playbar receding
- } else if ( previousTime > currentTime ) {
-
- while ( tracksByStart[ tracks.startIndex ] && tracksByStart[ tracks.startIndex ].start > currentTime ) {
- // if plugin does not exist on this instance, remove it
- if ( !tracksByStart[ tracks.startIndex ]._natives ||
- ( !!Popcorn.registryByName[ tracksByStart[ tracks.startIndex ]._natives.type ] ||
- !!that[ tracksByStart[ tracks.startIndex ]._natives.type ] ) ) {
-
- if ( tracksByStart[ tracks.startIndex ]._running === true ) {
- tracksByStart[ tracks.startIndex ]._running = false;
- tracksByStart[ tracks.startIndex ]._natives.end.call( that, event, tracksByStart[ tracks.startIndex ] );
- }
- tracks.startIndex--;
- } else {
- // remove track event
- Popcorn.removeTrackEvent( that, tracksByStart[ tracks.startIndex ]._id );
- return;
- }
- }
-
- while ( tracksByEnd[ tracks.endIndex ] && tracksByEnd[ tracks.endIndex ].end > currentTime ) {
- // if plugin does not exist on this instance, remove it
- if ( !tracksByEnd[ tracks.endIndex ]._natives ||
- ( !!Popcorn.registryByName[ tracksByEnd[ tracks.endIndex ]._natives.type ] ||
- !!that[ tracksByEnd[ tracks.endIndex ]._natives.type ] ) ) {
-
- if ( tracksByEnd[ tracks.endIndex ].start <= currentTime &&
- tracksByEnd[ tracks.endIndex ]._running === false &&
- that.data.disabled.indexOf( tracksByEnd[ tracks.endIndex ]._natives.type ) === -1 ) {
-
- tracksByEnd[ tracks.endIndex ]._running = true;
- tracksByEnd[ tracks.endIndex ]._natives.start.call( that, event, tracksByEnd[tracks.endIndex] );
- }
- tracks.endIndex--;
- } else {
- // remove track event
- Popcorn.removeTrackEvent( that, tracksByEnd[ tracks.endIndex ]._id );
- return;
- }
- }
- }
-
- tracks.previousUpdateTime = currentTime;
-
+ Popcorn.timeUpdate( that, event );
}, false );
} else {
global.setTimeout(function() {
@@ -965,6 +873,104 @@
return obj.data.history[ obj.data.history.length - 1 ];
};
+ Popcorn.timeUpdate = function( obj, event ) {
+
+ var currentTime = obj.media.currentTime,
+ previousTime = obj.data.trackEvents.previousUpdateTime,
+ tracks = obj.data.trackEvents,
+ tracksByEnd = tracks.byEnd,
+ tracksByStart = tracks.byStart;
+
+ // Playbar advancing
+ if ( previousTime < currentTime ) {
+
+ while ( tracksByEnd[ tracks.endIndex ] && tracksByEnd[ tracks.endIndex ].end <= currentTime ) {
+ // If plugin does not exist on this instance, remove it
+ if ( !tracksByEnd[ tracks.endIndex ]._natives ||
+ ( !!Popcorn.registryByName[ tracksByEnd[ tracks.endIndex ]._natives.type ] ||
+ !!obj[ tracksByEnd[ tracks.endIndex ]._natives.type ] ) ) {
+
+ if ( tracksByEnd[ tracks.endIndex ]._running === true ) {
+ tracksByEnd[ tracks.endIndex ]._running = false;
+ tracksByEnd[ tracks.endIndex ]._natives.end.call( obj, event, tracksByEnd[ tracks.endIndex ] );
+ }
+ tracks.endIndex++;
+ } else {
+ // remove track event
+ Popcorn.removeTrackEvent( obj, tracksByEnd[ tracks.endIndex ]._id );
+ return;
+ }
+ }
+
+ while ( tracksByStart[ tracks.startIndex ] && tracksByStart[ tracks.startIndex ].start <= currentTime ) {
+ // If plugin does not exist on this instance, remove it
+ if ( !tracksByStart[ tracks.startIndex ]._natives ||
+ ( !!Popcorn.registryByName[ tracksByStart[ tracks.startIndex ]._natives.type ] ||
+ !!obj[ tracksByStart[ tracks.startIndex ]._natives.type ] ) ) {
+
+ if ( tracksByStart[ tracks.startIndex ].end > currentTime &&
+ tracksByStart[ tracks.startIndex ]._running === false &&
+ obj.data.disabled.indexOf( tracksByStart[ tracks.startIndex ]._natives.type ) === -1 ) {
+
+ tracksByStart[ tracks.startIndex ]._running = true;
+ tracksByStart[ tracks.startIndex ]._natives.start.call( obj, event, tracksByStart[ tracks.startIndex ] );
+ }
+ tracks.startIndex++;
+ } else {
+ // remove track event
+ Popcorn.removeTrackEvent( obj, tracksByStart[ tracks.startIndex ]._id );
+ return;
+ }
+ }
+
+ // Playbar receding
+ } else if ( previousTime > currentTime ) {
+
+ while ( tracksByStart[ tracks.startIndex ] && tracksByStart[ tracks.startIndex ].start > currentTime ) {
+ // if plugin does not exist on this instance, remove it
+ if ( !tracksByStart[ tracks.startIndex ]._natives ||
+ ( !!Popcorn.registryByName[ tracksByStart[ tracks.startIndex ]._natives.type ] ||
+ !!obj[ tracksByStart[ tracks.startIndex ]._natives.type ] ) ) {
+
+ if ( tracksByStart[ tracks.startIndex ]._running === true ) {
+ tracksByStart[ tracks.startIndex ]._running = false;
+ tracksByStart[ tracks.startIndex ]._natives.end.call( obj, event, tracksByStart[ tracks.startIndex ] );
+ }
+ tracks.startIndex--;
+ } else {
+ // remove track event
+ Popcorn.removeTrackEvent( obj, tracksByStart[ tracks.startIndex ]._id );
+ return;
+ }
+ }
+
+ while ( tracksByEnd[ tracks.endIndex ] && tracksByEnd[ tracks.endIndex ].end > currentTime ) {
+ // if plugin does not exist on this instance, remove it
+ if ( !tracksByEnd[ tracks.endIndex ]._natives ||
+ ( !!Popcorn.registryByName[ tracksByEnd[ tracks.endIndex ]._natives.type ] ||
+ !!obj[ tracksByEnd[ tracks.endIndex ]._natives.type ] ) ) {
+
+ if ( tracksByEnd[ tracks.endIndex ].start <= currentTime &&
+ tracksByEnd[ tracks.endIndex ]._running === false &&
+ obj.data.disabled.indexOf( tracksByEnd[ tracks.endIndex ]._natives.type ) === -1 ) {
+
+ tracksByEnd[ tracks.endIndex ]._running = true;
+ tracksByEnd[ tracks.endIndex ]._natives.start.call( obj, event, tracksByEnd[tracks.endIndex] );
+ }
+ tracks.endIndex--;
+ } else {
+ // remove track event
+ Popcorn.removeTrackEvent( obj, tracksByEnd[ tracks.endIndex ]._id );
+ return;
+ }
+ }
+ // time bar is not moving ( video is paused )
+ }
+
+ tracks.previousUpdateTime = currentTime;
+
+ };
+
// Map and Extend TrackEvent functions to all Popcorn instances
Popcorn.extend( Popcorn.p, {
@@ -989,6 +995,11 @@
removePlugin: function( name ) {
Popcorn.removePlugin.call( null, this, name );
return this;
+ },
+
+ timeUpdate: function( event ) {
+ Popcorn.timeUpdate.call( null, this, event );
+ return this;
}
});

0 comments on commit c243c50

Please sign in to comment.