return;
}
- return "http://www.youtube.com/e/" + id+ "?enablejsapi=1&playerapiid=" + playerId + "&verion=3";
+ return "http://www.youtube.com/e/" + id;
}
function makeSWF( url, container ) {
// The video id for youtube (web or player formats)
// First check manually given url, if that doesn't work resort to "src"
- this.vidId = extractIdFromUrl( url ) || extractIdFromUri( url )
- || extractIdFromUrl( container.getAttribute( "src" ) ) || extractIdFromUri( container.getAttribute( "src" ) );
+ this.vidId = this.vidId || extractIdFromUrl( container.getAttribute( "src" ) ) || extractIdFromUri( container.getAttribute( "src" ) );
+
+ if ( !this.vidId ) {
+ throw "Could not find video id";
+ }
// Determine width/height/etc based on container
this.width = container.getAttribute("width") || 460;
this.offsetLeft = container.offsetLeft;
this.offsetTop = container.offsetTop;
- if ( !this.vidId ) {
- throw "Could not find video id";
- }
-
flashvars = {
playerapiid: this.playerId
};
};
swfobject.embedSWF( "http://www.youtube.com/e/" + this.vidId +"?enablejsapi=1&playerapiid=" + this.playerId + "&verion=3",
- this.playerId, this.width, this.height, "9.0.0", "expressInstall.swf", flashvars, params, attributes );
+ this.playerId, this.width, this.height, "8", null, flashvars, params, attributes );
}
// Called when a player is loaded
// Video hadn't loaded yet when ctor was called
vid.video = document.getElementById( playerId );
-
- // For calculating position relative to video (like subtitles)
- vid.offsetWidth = vid.video.offsetWidth;
- vid.offsetHeight = vid.video.offsetHeight;
- vid.offsetParent = vid.video.offsetParent;
- vid.offsetLeft = vid.video.offsetLeft;
- vid.offsetTop = vid.video.offsetTop;
-
vid.duration = vid.video.getDuration();
- // Set up stuff that requires the API to be loaded
- vid.registerYoutubeEventHandlers();
- vid.registerInternalEventHandlers();
-
// Issue load event
vid.dispatchEvent( 'load' );
vid.dispatchEvent( "durationchange" );
this.currentTime = this.previousCurrentTime = 0;
this.volume = this.previousVolume = this.preMuteVol = 1;
- this.duration = Number.MAX_VALUE;
+ this.duration = 0;
+
+ this.vidId = extractIdFromUrl( url ) || extractIdFromUri( url );
- if ( container ) {
+ this.addEventListener( "load", function() {
+ // For calculating position relative to video (like subtitles)
+ this.offsetWidth = this.video.offsetWidth;
+ this.offsetHeight = this.video.offsetHeight;
+ this.offsetParent = this.video.offsetParent;
+ this.offsetLeft = this.video.offsetLeft;
+ this.offsetTop = this.video.offsetTop;
+
+ // Set up stuff that requires the API to be loaded
+ this.registerYoutubeEventHandlers();
+ this.registerInternalEventHandlers();
+ });
+
+ (function() {
+ var hasBeenCalled = 0;
+
+ self.addEventListener( "playing", function() {
+ if (hasBeenCalled) {
+ return;
+ }
+
+ hasBeenCalled = 1;
+ self.duration = self.video.getDuration();
+ self.dispatchEvent( "durationchange" );
+
+ });
+ })();
+
+ if ( loadedPlayers[this.playerId] ) {
+ this.video = registry[this.playerId].video;
+
+ this.vidId = this.vidId || extractIdFromUrl( container.getAttribute( "src" ) ) || extractIdFromUri( container.getAttribute( "src" ) );
+
+ if (this.vidId !== registry[this.playerId].vidId ) {
+ this.video.cueVideoById( this.vidId );
+ } else {
+ // Same video, new ctor. Force a seek to the beginning
+ this.previousCurrentTime = 1;
+ }
+
+ this.dispatchEvent( 'load' );
+ } else if ( container ) {
makeSWF.call( this, url, container );
} else {
// Container not yet loaded, get it on DOMDontentLoad
}
registry[this.playerId] = this;
-
- if ( loadedPlayers[this.playerId] ) {
- this.dispatchEvent( "load" );
- }
};
// end Popcorn.youtube.init
play: function() {
// In case called before video is loaded, defer acting
if ( !loadedPlayers[this.playerId] ) {
- this.addEventListener( "load", this.play );
+ this.addEventListener( "load", function() {
+ this.play();
+ });
return;
}
load: function() {
// In case called before video is loaded, defer acting
if ( !loadedPlayers[this.playerId] ) {
- this.addEventListener( "load", this.load );
+ this.addEventListener( "load", function() {
+ this.load();
+} );
return;
}
this.dispatchEvent( 'progress' );
setTimeout( function() {
- self.startTimeUpdater.call( self );
+ self.startProgressUpdater.call( self );
}, progressInterval);
}
}); // end Popcorn.extend
set1Executed = false,
set2Executed = false,
set3Executed = false,
- expects = expectedEvents.length + 5;
+ expects = expectedEvents.length + 5,
+ listeners = [];
stop( 15000 );
expect(expects);
}
}
- popcorn.listen( event, function() {
- eventCount++;
- var expected = expectedEvents.shift();
- if ( expected == event ) {
- ok( true, "Event: "+event + " is fired." );
- plus();
- } else {
- ok( false, event + " is fired unexpectedly, expecting: " + expected );
- }
+ listeners.push( {
+ evt: event,
+ fn: popcorn.listen( event, function() {
+ eventCount++;
+ var expected = expectedEvents.shift();
+ if ( expected == event ) {
+ ok( true, "Event: "+event + " is fired." );
+ plus();
+ } else {
+ ok( false, event + " is fired unexpectedly, expecting: " + expected );
+ }
+ })
});
added.push( event );
})( expectedEvents[i] );
}
+
+ // Cleanup
+ listeners.push( popcorn.listen( "ended", function() {
+ Popcorn.forEach( listeners, function ( obj ) {
+ popcorn.unlisten( obj.evt, obj.fn );
+ });
+ }));
// operations set1
popcorn.listen( 'playing', function() {
QUnit.reset();
var count = 0,
- expects = 4,
- rawTube = Popcorn.youtube( 'video', 'http://www.youtube.com/watch?v=9oar9glUCL0' );
+ expects = 3,
+ popcorn = Popcorn( Popcorn.youtube( 'video2', 'http://www.youtube.com/watch?v=9oar9glUCL0' ) );
expect( expects );
- stop( 5000 );
+ stop( 10000 );
- equals( rawTube.vidId, '9oar9glUCL0', 'Video id set' );
+ equals( popcorn.video.vidId, '9oar9glUCL0', 'Video id set' );
plus();
- equals( rawTube.duration, Number.MAX_VALUE, 'Duration starts as Max Value');
+ equals( popcorn.duration(), 0, 'Duration starts as 0');
plus();
- rawTube.addEventListener( "playing", function() {
- notEqual( rawTube.duration, Number.MAX_VALUE, "Duration has been changed from max value" );
- plus();
- notEqual( rawTube.duration, 0, "Duration is non-zero" );
+ popcorn.listen( "durationchange", function() {
+ notEqual( 0, popcorn.duration(), "Duration has been changed from 0" );
plus();
- rawTube.pause();
+ popcorn.pause();
});
- rawTube.play();
+ popcorn.play();
});
\ No newline at end of file