Permalink
Browse files

Baseplayer can now update players with state info after a player is r…

…eady. Also, updates to enable this in the Youtube Player. [#743]
  • Loading branch information...
2 parents 6341634 + 90295a8 commit caa6b79129fc99c4383bb535b558bc99da10e16e @cadecairos cadecairos committed Sep 29, 2011
Showing with 58 additions and 20 deletions.
  1. +1 −14 players/youtube/popcorn.youtube.js
  2. +6 −1 players/youtube/popcorn.youtube.unit.js
  3. +51 −5 popcorn.js
@@ -14,7 +14,6 @@ Popcorn.player( "youtube", {
currentTime = 0,
seekTime = 0,
seeking = false,
- dataLoaded = false,
// state code for volume changed polling
volumeChanged = false,
@@ -100,12 +99,6 @@ Popcorn.player( "youtube", {
media.paused = false;
media.dispatchEvent( "play" );
- if ( dataLoaded ) {
-
- media.dispatchEvent( "loadeddata" );
- dataLoaded = false;
- }
-
media.dispatchEvent( "playing" );
timeupdate();
youtubeObject.playVideo();
@@ -183,17 +176,11 @@ Popcorn.player( "youtube", {
media.readyState = 4;
media.dispatchEvent( "load" );
- dataLoaded = true;
media.duration = youtubeObject.getDuration();
media.dispatchEvent( "durationchange" );
volumeupdate();
- if ( !media.paused ) {
-
- media.play();
- }
-
- media.paused && media.dispatchEvent( "loadeddata" );
+ media.dispatchEvent( "loadeddata" );
};
options.controls = +options.controls === 0 || +options.controls === 1 ? options.controls : 1;
@@ -161,7 +161,12 @@ test("Update Timer", function () {
}
});
- p2.currentTime(3).play();
+ p2.exec( 3, function() {
+
+ p2.play();
+ });
+
+ p2.currentTime(3);
});
View
@@ -1525,6 +1525,8 @@
var date = new Date() / 1000,
baselineTime = date,
currentTime = 0,
+ volume = 1,
+ muted = false,
events = {},
// The container div of the resource
@@ -1613,6 +1615,36 @@
configurable: true
});
+ Popcorn.player.defineProperty( basePlayer, "volume", {
+ get: function() {
+
+ return volume;
+ },
+ set: function( val ) {
+
+ // make sure val is a number
+ volume = +val;
+ basePlayer.dispatchEvent( "volumechange" );
+ return volume;
+ },
+ configurable: true
+ });
+
+ Popcorn.player.defineProperty( basePlayer, "muted", {
+ get: function() {
+
+ return muted;
+ },
+ set: function( val ) {
+
+ // make sure val is a number
+ muted = +val;
+ basePlayer.dispatchEvent( "volumechange" );
+ return muted;
+ },
+ configurable: true
+ });
+
// Adds an event listener to the object
basePlayer.addEventListener = function( evtName, fn ) {
@@ -1659,20 +1691,34 @@
basePlayer.paused = true;
basePlayer.ended = 0;
- // basePlayer has no concept of sound
- basePlayer.volume = 1;
- basePlayer.muted = false;
-
if ( player._setup ) {
player._setup.call( basePlayer, options );
} else {
// there is no setup, which means there is nothing to load
basePlayer.readyState = 4;
- basePlayer.dispatchEvent( 'load' );
+ basePlayer.dispatchEvent( "load" );
+ basePlayer.dispatchEvent( "loadeddata" );
}
+ // when a custom player is loaded, load basePlayer state into custom player
+ basePlayer.addEventListener( "load", function() {
+
+ // if a player is not ready before currentTime is called, this will set it after it is ready
+ basePlayer.currentTime = currentTime;
+
+ // same as above with volume and muted
+ basePlayer.volume = volume;
+ basePlayer.muted = muted;
+ });
+
+ basePlayer.addEventListener( "loadeddata", function() {
+
+ // if play was called before player ready, start playing video
+ !basePlayer.paused && basePlayer.play();
+ });
+
popcorn = new Popcorn.p.init( basePlayer, options );
return popcorn;

0 comments on commit caa6b79

Please sign in to comment.