]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
Added new timeUpdate branch
authorDavid Seifried <david.c.seifried@gmail.com>
Wed, 24 Aug 2011 18:52:39 +0000 (14:52 -0400)
committerDavid Seifried <david.c.seifried@gmail.com>
Wed, 24 Aug 2011 18:52:39 +0000 (14:52 -0400)
popcorn.js

index 92cbfdf06d7bde90ea6f9f6f9cf167090dbd2861..54592f83dbf76ab3a0deac10efcaf8eb31833159 100644 (file)
           });
 
           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 || !!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 || !!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 || !!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 || !!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() {
     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 || !!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 || !!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 || !!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 || !!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, {
 
     removePlugin: function( name ) {
       Popcorn.removePlugin.call( null, this, name );
       return this;
+    },
+
+    timeUpdate: function( event ) {
+      Popcorn.timeUpdate.call( null, this, event );
+      return this; 
     }
   });