From: Rick Waldron Date: Tue, 6 Sep 2011 15:35:47 +0000 (-0400) Subject: Reduced code inside Popcorn.timeUpdate X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=ec5e7861a81d3bbf49e458a45fe4abc2b0467c01;p=popcorn-js.git Reduced code inside Popcorn.timeUpdate --- diff --git a/popcorn.js b/popcorn.js index 51659a7..21de7bd 100644 --- a/popcorn.js +++ b/popcorn.js @@ -875,50 +875,73 @@ 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; + var currentTime = obj.media.currentTime, + previousTime = obj.data.trackEvents.previousUpdateTime, + tracks = obj.data.trackEvents, + tracksBy = { + start: tracks.byStart, + end: tracks.byEnd + }, + + end = tracks.endIndex, + start = tracks.startIndex, + + registryByName = Popcorn.registryByName; + // Playbar advancing if ( previousTime < currentTime ) { - while ( tracksByEnd[ tracks.endIndex ] && tracksByEnd[ tracks.endIndex ].end <= currentTime ) { + + + + + while ( tracksBy.end[ end ] && tracksBy.end[ end ].end <= currentTime ) { + + var byEnd = tracksBy.end[ end ], + natives = byEnd._natives, + type = natives && natives.type; + // 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 ( !natives || + ( !!registryByName[ type ] || + !!obj[ type ] ) ) { - if ( tracksByEnd[ tracks.endIndex ]._running === true ) { - tracksByEnd[ tracks.endIndex ]._running = false; - tracksByEnd[ tracks.endIndex ]._natives.end.call( obj, event, tracksByEnd[ tracks.endIndex ] ); + if ( byEnd._running === true ) { + byEnd._running = false; + natives.end.call( obj, event, byEnd ); } - tracks.endIndex++; + + end++; } else { // remove track event - Popcorn.removeTrackEvent( obj, tracksByEnd[ tracks.endIndex ]._id ); + Popcorn.removeTrackEvent( obj, byEnd._id ); return; } } - while ( tracksByStart[ tracks.startIndex ] && tracksByStart[ tracks.startIndex ].start <= currentTime ) { + while ( tracksBy.start[ start ] && tracksBy.start[ start ].start <= currentTime ) { + + var byStart = tracksBy.start[ start ], + natives = byStart._natives, + type = natives && natives.type; + // 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 ( !natives || + ( !!registryByName[ type ] || + !!obj[ type ] ) ) { - if ( tracksByStart[ tracks.startIndex ].end > currentTime && - tracksByStart[ tracks.startIndex ]._running === false && - obj.data.disabled.indexOf( tracksByStart[ tracks.startIndex ]._natives.type ) === -1 ) { + if ( byStart.end > currentTime && + byStart._running === false && + obj.data.disabled.indexOf( type ) === -1 ) { - tracksByStart[ tracks.startIndex ]._running = true; - tracksByStart[ tracks.startIndex ]._natives.start.call( obj, event, tracksByStart[ tracks.startIndex ] ); + byStart._running = true; + natives.start.call( obj, event, byStart ); } - tracks.startIndex++; + start++; } else { // remove track event - Popcorn.removeTrackEvent( obj, tracksByStart[ tracks.startIndex ]._id ); + Popcorn.removeTrackEvent( obj, byStart._id ); return; } } @@ -926,47 +949,61 @@ // Playbar receding } else if ( previousTime > currentTime ) { - while ( tracksByStart[ tracks.startIndex ] && tracksByStart[ tracks.startIndex ].start > currentTime ) { + while ( tracksBy.start[ start ] && tracksBy.start[ start ].start > currentTime ) { + + var byStart = tracksBy.start[ start ], + natives = byStart._natives, + type = natives && natives.type; + // 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 ( !natives || + ( !!registryByName[ type ] || + !!obj[ type ] ) ) { - if ( tracksByStart[ tracks.startIndex ]._running === true ) { - tracksByStart[ tracks.startIndex ]._running = false; - tracksByStart[ tracks.startIndex ]._natives.end.call( obj, event, tracksByStart[ tracks.startIndex ] ); + if ( byStart._running === true ) { + byStart._running = false; + natives.end.call( obj, event, byStart ); } - tracks.startIndex--; + start--; } else { // remove track event - Popcorn.removeTrackEvent( obj, tracksByStart[ tracks.startIndex ]._id ); + Popcorn.removeTrackEvent( obj, byStart._id ); return; } } - while ( tracksByEnd[ tracks.endIndex ] && tracksByEnd[ tracks.endIndex ].end > currentTime ) { + while ( tracksBy.end[ end ] && tracksBy.end[ end ].end > currentTime ) { + + var byEnd = tracksBy.end[ end ], + natives = byEnd._natives, + type = natives && natives.type; + // 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 ( !natives || + ( !!registryByName[ type ] || + !!obj[ type ] ) ) { - if ( tracksByEnd[ tracks.endIndex ].start <= currentTime && - tracksByEnd[ tracks.endIndex ]._running === false && - obj.data.disabled.indexOf( tracksByEnd[ tracks.endIndex ]._natives.type ) === -1 ) { + if ( byEnd.start <= currentTime && + byEnd._running === false && + obj.data.disabled.indexOf( type ) === -1 ) { - tracksByEnd[ tracks.endIndex ]._running = true; - tracksByEnd[ tracks.endIndex ]._natives.start.call( obj, event, tracksByEnd[tracks.endIndex] ); + byEnd._running = true; + natives.start.call( obj, event, byEnd ); } - tracks.endIndex--; + end--; } else { // remove track event - Popcorn.removeTrackEvent( obj, tracksByEnd[ tracks.endIndex ]._id ); + Popcorn.removeTrackEvent( obj, byEnd._id ); return; } } // time bar is not moving ( video is paused ) + } else if ( previousTime === currentTime ) { + } + tracks.endIndex = end; + tracks.startIndex = start; tracks.previousUpdateTime = currentTime; }; @@ -999,7 +1036,7 @@ timeUpdate: function( event ) { Popcorn.timeUpdate.call( null, this, event ); - return this; + return this; } });