this.timeUpdater = null;
this.progressUpdater = null;
+ this.currentTime = 0;
+ this.previousCurrentTime = 0;
+ this.volume = 0;
+ this.previousVolume = 0;
+
this.playerId = elementId;
this.duration = Number.MAX_VALUE;
// Start current time and loading progress syncing intervals.
registerInternalEventHandlers: function() {
this.addEventListener( 'playing', function() {
- startTimeUpdater( this );
+ this.startTimeUpdater();
});
this.addEventListener( 'loadedmetadata', function() {
- startProgressUpdater( this );
+ this.startProgressUpdater();
});
},
this.video.playVideo();
this.video.pauseVideo();
},
-
- currentTime: 0,
- previousCurrentTime: 0,
seekTo: function( time ) {
var playing = this.video.getPlayerState() == YOUTUBE_STATE_PLAYING;
mute: function() {
if ( this.video.isMuted() ) {
this.video.unMute();
+ this.volume = this.video.getVolume() / 100;
this.dispatchEvent( 'volumechange' );
} else {
this.video.mute();
+ this.volume = 0;
this.dispatchEvent( 'volumechange' );
}
},
-
- volume: 0,
- previousVolume: 0,
// Expects beteween 0 and 1
setVolume: function( vol ) {
},
playbackRate: function( arg ) {
- }
-
- }); // end Popcorn.extend
-
- function startTimeUpdater( youcorn ) {
- youcorn.timeUpdater = setInterval(function() {
-
- var state = youcorn.video.getPlayerState();
-
+ },
+
+ startTimeUpdater: function() {
+ var state = this.video.getPlayerState(),
+ self = this,
+ seeked = 0;
+ if ( abs( this.currentTime - this.previousCurrentTime ) > timeCheckInterval ) {
+ // Has programatically set the currentTime
+ this.previousCurrentTime = this.currentTime - timeCheckInterval;
+ this.seekTo( this.currentTime );
+ seeked = 1;
+ } else {
+ this.previousCurrentTime = this.currentTime;
+ this.currentTime = this.video.getCurrentTime();
+ }
- if ( state !== YOUTUBE_STATE_ENDED && state !== YOUTUBE_STATE_PAUSED ) {
- if ( abs( youcorn.currentTime - youcorn.previousCurrentTime ) > timeCheckInterval ) {
- // Has programatically set the currentTime
- youcorn.previousCurrentTime = youcorn.currentTime - timeCheckInterval;
- youcorn.seekTo( youcorn.currentTime );
- } else {
- youcorn.previousCurrentTime = youcorn.currentTime;
- youcorn.currentTime = youcorn.video.getCurrentTime();
- }
+ if ( this.volume !== this.previousVolume ) {
+ this.setVolume( this.volume );
}
- if ( youcorn.volume !== youcorn.previousVolume ) {
- youcorn.setVolume( youcorn.volume );
+ if ( state !== YOUTUBE_STATE_ENDED && state !== YOUTUBE_STATE_PAUSED || seeked ) {
+ this.dispatchEvent( 'timeupdate' );
}
- youcorn.dispatchEvent( 'timeupdate' );
- }, timeupdateInterval);
- }
-
- function startProgressUpdater( youcorn ) {
- youcorn.progressUpdater = setInterval(function() {
- var bytesLoaded = youcorn.video.getVideoBytesLoaded(),
- bytesToLoad = youcorn.video.getVideoBytesTotal();
+ if( state !== YOUTUBE_STATE_ENDED ) {
+ setTimeout( function() {
+ self.startTimeUpdater.call(self);
+ }, timeupdateInterval);
+ }
+ },
+
+ startProgressUpdater: function() {
+ var bytesLoaded = this.video.getVideoBytesLoaded(),
+ bytesToLoad = this.video.getVideoBytesTotal(),
+ self = this;
// do nothing if size is not yet determined
if ( bytesToLoad == 0 ) {
}
// raise an event if load has just started
- if ( !youcorn.loadStarted ) {
- youcorn.loadStarted = true;
- youcorn.dispatchEvent( 'loadstart' );
+ if ( !this.loadStarted ) {
+ this.loadStarted = true;
+ this.dispatchEvent( 'loadstart' );
}
// fully loaded
if ( bytesLoaded >= bytesToLoad ) {
- youcorn.fullyLoaded = true;
- youcorn.readyState = READY_STATE_HAVE_ENOUGH_DATA;
- youcorn.dispatchEvent( 'canplaythrough' );
- clearInterval( youcorn.progressUpdater );
+ this.fullyLoaded = true;
+ this.readyState = READY_STATE_HAVE_ENOUGH_DATA;
+ this.dispatchEvent( 'canplaythrough' );
return;
}
- youcorn.dispatchEvent( 'progress' );
- }, progressInterval);
- }
+ this.dispatchEvent( 'progress' );
+
+ setTimeout( function() {
+ self.startTimeUpdater.call( self );
+ }, progressInterval);
+ }
+ }); // end Popcorn.extend
/* Unsupported properties and events. */
return;
}
+ function plus(){
+ if ( ++count == expects ) {
+ start();
+ }
+ }
+
+ QUnit.reset();
+
+ var count = 0,
+ expects = 19;
+
+ stop( 15000 );
+
popcorn.volume(1); // is muted later
// check time sync
popcorn.exec(2, function() {
ok( popcorn.currentTime() >= 2, "Check time synchronization." );
+ plus();
});
popcorn.exec(49, function() {
ok( popcorn.currentTime() >= 49, "Check time synchronization." );
+ plus();
});
popcorn.exec(40, function() {
ok( false, "This should not be run." );
var expectedEvents = [
'play',
'loadeddata',
+ 'volumechange',
'playing',
'volumechange',
'pause',
'seeked',
'volumechange',
'volumechange',
- 'volumechange',
'playing',
'pause',
'ended'
eventCount++;
var expected = expectedEvents.shift();
if ( expected == event ) {
- ok( true, event + " is fired." );
+ ok( true, "Event: "+event + " is fired." );
+ plus();
} else {
- ok( false, event + " is fired, expecting: " + expected );
+ ok( false, event + " is fired unexpectedly, expecting: " + expected );
}
});
added.push( event );
return;
}
- popcorn.volume(1);
+ popcorn.volume(0.5);
popcorn.mute();
equals( popcorn.volume(), 0, "Muted" );
+ plus();
popcorn.mute();
ok( popcorn.volume() !== 0, "Not Muted" );
- equals( popcorn.volume(), 1, "Back to volume of 1" );
+ plus();
+
+ equals( popcorn.volume(), 0.5, "Back to volume of 1" );
+ plus();
set3Executed = true;
});
-
- var time = 0,
- wait = 100,
- timeout = 15000;
-
- stop( timeout + wait );
- var interval = setInterval( function() {
- time += wait;
- if ( time > timeout ) {
- clearInterval( interval );
- return;
- }
- if ( eventCount == expectedEventCount ) {
- start();
- clearInterval( interval );
- }
- }, wait );
});
test( "Popcorn YouTube Plugin Url and Duration Tests", function() {
});
rawTube.play();
-
});
\ No newline at end of file