Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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...
commit caa6b79129fc99c4383bb535b558bc99da10e16e 2 parents 6341634 + 90295a8
Christopher De Cairos authored
15  players/youtube/popcorn.youtube.js
@@ -14,7 +14,6 @@ Popcorn.player( "youtube", {
14 14
         currentTime = 0,
15 15
         seekTime = 0,
16 16
         seeking = false,
17  
-        dataLoaded = false,
18 17
 
19 18
         // state code for volume changed polling
20 19
         volumeChanged = false,
@@ -100,12 +99,6 @@ Popcorn.player( "youtube", {
100 99
           media.paused = false;
101 100
           media.dispatchEvent( "play" );
102 101
 
103  
-          if ( dataLoaded ) {
104  
-
105  
-            media.dispatchEvent( "loadeddata" );
106  
-            dataLoaded = false;
107  
-          }
108  
-
109 102
           media.dispatchEvent( "playing" );
110 103
           timeupdate();
111 104
           youtubeObject.playVideo();
@@ -183,17 +176,11 @@ Popcorn.player( "youtube", {
183 176
 
184 177
         media.readyState = 4;
185 178
         media.dispatchEvent( "load" );
186  
-        dataLoaded = true;
187 179
         media.duration = youtubeObject.getDuration();
188 180
         media.dispatchEvent( "durationchange" );
189 181
         volumeupdate();
190 182
 
191  
-        if ( !media.paused ) {
192  
-
193  
-          media.play();
194  
-        }
195  
-
196  
-        media.paused && media.dispatchEvent( "loadeddata" );
  183
+        media.dispatchEvent( "loadeddata" );
197 184
       };
198 185
 
199 186
       options.controls = +options.controls === 0 || +options.controls === 1 ? options.controls : 1;
7  players/youtube/popcorn.youtube.unit.js
@@ -161,7 +161,12 @@ test("Update Timer", function () {
161 161
     }
162 162
   });
163 163
 
164  
-  p2.currentTime(3).play();
  164
+  p2.exec( 3, function() {
  165
+
  166
+    p2.play();
  167
+  });
  168
+
  169
+  p2.currentTime(3);
165 170
 
166 171
 });
167 172
 
56  popcorn.js
@@ -1525,6 +1525,8 @@
1525 1525
       var date = new Date() / 1000,
1526 1526
           baselineTime = date,
1527 1527
           currentTime = 0,
  1528
+          volume = 1,
  1529
+          muted = false,
1528 1530
           events = {},
1529 1531
 
1530 1532
           // The container div of the resource
@@ -1613,6 +1615,36 @@
1613 1615
         configurable: true
1614 1616
       });
1615 1617
 
  1618
+      Popcorn.player.defineProperty( basePlayer, "volume", {
  1619
+        get: function() {
  1620
+
  1621
+          return volume;
  1622
+        },
  1623
+        set: function( val ) {
  1624
+
  1625
+          // make sure val is a number
  1626
+          volume = +val;
  1627
+          basePlayer.dispatchEvent( "volumechange" );
  1628
+          return volume;
  1629
+        },
  1630
+        configurable: true
  1631
+      });
  1632
+
  1633
+      Popcorn.player.defineProperty( basePlayer, "muted", {
  1634
+        get: function() {
  1635
+
  1636
+          return muted;
  1637
+        },
  1638
+        set: function( val ) {
  1639
+
  1640
+          // make sure val is a number
  1641
+          muted = +val;
  1642
+          basePlayer.dispatchEvent( "volumechange" );
  1643
+          return muted;
  1644
+        },
  1645
+        configurable: true
  1646
+      });
  1647
+
1616 1648
       // Adds an event listener to the object
1617 1649
       basePlayer.addEventListener = function( evtName, fn ) {
1618 1650
 
@@ -1659,10 +1691,6 @@
1659 1691
       basePlayer.paused = true;
1660 1692
       basePlayer.ended = 0;
1661 1693
 
1662  
-      // basePlayer has no concept of sound
1663  
-      basePlayer.volume = 1;
1664  
-      basePlayer.muted = false;
1665  
-
1666 1694
       if ( player._setup ) {
1667 1695
 
1668 1696
         player._setup.call( basePlayer, options );
@@ -1670,9 +1698,27 @@
1670 1698
 
1671 1699
         // there is no setup, which means there is nothing to load
1672 1700
         basePlayer.readyState = 4;
1673  
-        basePlayer.dispatchEvent( 'load' );
  1701
+        basePlayer.dispatchEvent( "load" );
  1702
+        basePlayer.dispatchEvent( "loadeddata" );
1674 1703
       }
1675 1704
 
  1705
+      // when a custom player is loaded, load basePlayer state into custom player
  1706
+      basePlayer.addEventListener( "load", function() {
  1707
+
  1708
+        // if a player is not ready before currentTime is called, this will set it after it is ready
  1709
+        basePlayer.currentTime = currentTime;
  1710
+
  1711
+        // same as above with volume and muted
  1712
+        basePlayer.volume = volume;
  1713
+        basePlayer.muted = muted;
  1714
+      });
  1715
+
  1716
+      basePlayer.addEventListener( "loadeddata", function() {
  1717
+
  1718
+        // if play was called before player ready, start playing video
  1719
+        !basePlayer.paused && basePlayer.play();
  1720
+      });
  1721
+
1676 1722
       popcorn = new Popcorn.p.init( basePlayer, options );
1677 1723
 
1678 1724
       return popcorn;

0 notes on commit caa6b79

Please sign in to comment.
Something went wrong with that request. Please try again.