]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
[#140] Updated for core engine changes
authorstevenaw <sweerdenburg@gmail.com>
Tue, 15 Mar 2011 15:44:58 +0000 (11:44 -0400)
committerstevenaw <sweerdenburg@gmail.com>
Tue, 15 Mar 2011 15:44:58 +0000 (11:44 -0400)
players/youtube/popcorn.youtube.html
players/youtube/popcorn.youtube.js
players/youtube/popcorn.youtube.unit.html
players/youtube/popcorn.youtube.unit.js
popcorn.js
test/popcorn.unit.js

index c3d83442d79f17489f2775890d75f964de1adf07..d874f24d35c0961a02aa075685ef3a69bd9a7fd2 100644 (file)
@@ -4,32 +4,36 @@
     <title>Popcorn Youtube Player Example</title>
       <script src="../../popcorn.js"></script>
       <script type="text/javascript" src="popcorn.youtube.js"></script>
+      <script src="../../plugins/footnote/popcorn.footnote.js"></script>
       <script>
-        // <![CDATA[
-
-        /* Some code on this page is taken from stevenaw's vimeo plug-in. */
-
         // Helper function to get elements
         function element(id) {
           return document.getElementById(id);
         }
-
-        // Register YouTube
-        function onYouTubePlayerReady() {
-          element( 'player-status' ).innerHTML = 'Ready';
-
-          var youcorn = Popcorn.youtube( 'video' );
-          var popcorn = Popcorn(youcorn);
-          element( 'player-duration' ).innerHTML = popcorn.duration();
-
+        
+        document.addEventListener( 'DOMContentLoaded', function() {
+          var popcorn = Popcorn( Popcorn.youtube( 'video', 'http://www.youtube.com/watch?v=9oar9glUCL0' ) );
+          
+          
+          popcorn.footnote({
+            start: 5, // seconds
+            end: 15, // seconds
+            text: 'Visit webmademovies.org for more details',
+            target: 'footnotediv'
+          });
+          
+          popcorn.listen( 'durationchange', function() {
+            element( 'player-duration' ).innerHTML = popcorn.duration();
+          });
+          
           // Update time
           popcorn.listen( 'timeupdate', function() {
             element( 'player-time' ).innerHTML = popcorn.currentTime();
           });
-
+          
           // Update button labels
           var paused = true;
-          popcorn.listen( 'play' , function() {
+          popcorn.listen( 'playing' , function() {
             paused = false;
             element( 'btn-play-pause' ).innerHTML = 'Pause';
           });
             paused = true;
             element( 'btn-play-pause' ).innerHTML = 'Play';
           });
+            
+          // Setup UI after loaded
+          popcorn.listen( 'load', function() {
+            element( 'player-status' ).innerHTML = 'Ready';
+            
+            // Single play/pause button
+            element( 'btn-play-pause' ).addEventListener( 'click', function() {
+              if ( paused ) {
+                popcorn.play();
+              } else {
+                popcorn.pause();
+              }
+            }, false);
 
-          // Single play/pause button
-          element( 'btn-play-pause' ).addEventListener( 'click', function() {
-            if (paused) {
-              popcorn.play();
-            } else {
-              popcorn.pause();
-            }
-          }, false);
-
-          // Seek
-          element('btn-seek').addEventListener('click', function() {
-            popcorn.currentTime(30);
-          }, false);
+            // Seek
+            element('btn-seek').addEventListener('click', function() {
+              popcorn.currentTime( 30 );
+            }, false);
 
-          // Volume
-          element('btn-volume').addEventListener('click', function() {
-            var volume = (popcorn.volume() === 1) ? 0.5 : 1;
-            popcorn.volume(volume);
-          }, false);
-        }
-      // ]]>
+            // Volume
+            element('btn-volume').addEventListener('click', function() {
+              var volume = (popcorn.volume() === 1) ? 0.5 : 1;
+              popcorn.volume(volume);
+            }, false);
+            
+            element('btn-mute').addEventListener('click', function() {
+              popcorn.mute();
+            }, false);
+          });
+        }, false );
     </script>
   </head>
   <body>
     <div>
       <object id="video" type="application/x-shockwave-flash"
-        data="http://www.youtube.com/e/ac7KhViaVqc?enablejsapi=1&amp;version=3"
+        data="http://www.youtube.com/e/ac7KhViaVqc?enablejsapi=1&playerapiid=video&version=3"
         width="250" height="200">
         <param name="allowFullScreen" value="true" />
         <param name="allowscriptaccess" value="always" />
@@ -74,6 +86,7 @@
       <button class="simple" id="btn-play-pause">Play</button>
       <button class="seek" id="btn-seek">Seek to 30</button>
       <button class="volume" id="btn-volume">Toggle Volume</button>
+      <button class="mute" id="btn-mute">Toggle Mute</button>
       <div>
         <ul>
           <li>Status: <span id="player-status">Not Ready</span></li>
@@ -81,6 +94,7 @@
           <li>Video Duration (s): <span id="player-duration"></span></li>
         </ul>
       </div>
+      Footnote:<br />
       <div id="footnotediv" width="50%" height="50%"></div>
     </div>
   </body>
index 2f7125c1ebf07500e9ce2134f8ad7a0ee6060a9c..b9aa7d57b9130ebb4dc287b90bc48a8637e8659f 100644 (file)
@@ -1,4 +1,6 @@
-// Popcorn Youtube Player Warpper
+// Popcorn Youtube Player Wrapper
+
+var onYouTubePlayerReady;
 
 ( function( Popcorn ) {
   /**
   var undef;
 
   // Config parameters
-  var debug = true;
-  var timeupdateInterval = 33; // 33 is suitable for 30 fps
-  var progressInterval = 250; // as specified by WHATWG
+  // 33 ms per update is suitable for 30 fps
+  // 0.05 sec tolerance between old and new times to determine if currentTime has been set programatically
+  // 250 ms progress interval as specified by WHATWG
+  var timeupdateInterval = 33,
+      timeCheckInterval = 0.5
+      progressInterval = 250;
 
   // Ready State Constants
-  var READY_STATE_HAVE_NOTHING = 0;
-  var READY_STATE_HAVE_METADATA = 1;
-  var READY_STATE_HAVE_CURRENT_DATA = 2;
-  var READY_STATE_HAVE_FUTURE_DATA = 3;
-  var READY_STATE_HAVE_ENOUGH_DATA = 4;
+  var READY_STATE_HAVE_NOTHING = 0,
+      READY_STATE_HAVE_METADATA = 1,
+      READY_STATE_HAVE_CURRENT_DATA = 2,
+      READY_STATE_HAVE_FUTURE_DATA = 3,
+      READY_STATE_HAVE_ENOUGH_DATA = 4;
 
   // Youtube State Constants
-  var YOUTUBE_STATE_UNSTARTED = -1;
-  var YOUTUBE_STATE_ENDED = 0;
-  var YOUTUBE_STATE_PLAYING = 1;
-  var YOUTUBE_STATE_PAUSED = 2;
-  var YOUTUBE_STATE_BUFFERING = 3;
-  var YOUTUBE_STATE_CUED = 5;
-
-  Popcorn.youtube = function( elementId ) {
-    return new Popcorn.youtube.init( elementId );
+  var YOUTUBE_STATE_UNSTARTED = -1,
+      YOUTUBE_STATE_ENDED = 0,
+      YOUTUBE_STATE_PLAYING = 1,
+      YOUTUBE_STATE_PAUSED = 2,
+      YOUTUBE_STATE_BUFFERING = 3,
+      YOUTUBE_STATE_CUED = 5;
+  
+  // Collection of all Youtube players
+  var registry = {},
+      loadedPlayers = {};
+      
+  var abs = Math.abs;
+  
+  // Extract the id from a web url
+  function extractIdFromUrl( url ) {
+    if ( !url ) {
+      return;
+    }
+    
+    var matches = url.match( /((http:\/\/)?www\.)?youtube\.[a-z]+\/watch\?v\=[a-z0-9]+/i );
+    
+    // Return id, which comes after first equals sign
+    return !matches || matches[0].split( "=" )[1];
   };
+  
+  function cueDelayedDurationCheck ( evt ) {
+    var self = this,
+        durSetEvt;
+        
+    durSetEvt = function() {
+      this.duration = this.video.getDuration();
+      this.dispatchEvent( "durationchange" );
+    };
+    
+    this.eventListeners[evt] = this.eventListeners[evt] || [];
+    
+    this.eventListeners[evt].unshift(durSetEvt);
+  }
+  
+  function getPlayerAddress( id ) {
+    if( !id ) {
+      return;
+    }
+    
+    return "http://www.youtube.com/e/"+id;
+  }
+  
+  // Called when a player is loaded
+  // Playerid must match the element id
+  onYouTubePlayerReady = function ( playerId ) {
+    var vid = registry[playerId];
+    
+    loadedPlayers[playerId] = 1;
+    
+    // Video hadn't loaded yet when ctor was called
+    if( !vid.video ) {
+      vid.video = document.getElementById( playerId );
+    }
+    
+    // Set up stuff that requires the API to be loaded
+    vid.registerYoutubeEventHandlers();
+    vid.registerInternalEventHandlers();
+    
+    // Issue load event
+    vid.dispatchEvent( 'load' );
+  }
 
-  Popcorn.youtube.init = function( elementId ) {
+  Popcorn.youtube = function( elementId, url ) {
+    return new Popcorn.youtube.init( elementId, url );
+  };
+
+  Popcorn.youtube.init = function( elementId, url ) {
     if ( !elementId ) {
       throw "Element id is invalid.";
     }
+    
+    var self = this,
+        durEvtType;
 
     this.video = document.getElementById( elementId );
     this.readyState = READY_STATE_HAVE_NOTHING;
-    this.duration = this.video.getDuration();
     this.eventListeners = {};
     this.loadStarted = false;
     this.loadedData = false;
     this.fullyLoaded = false;
     this.timeUpdater = null;
     this.progressUpdater = null;
-    this.registerYoutubeEventHandlers();
-    this.registerInternalEventHandlers();
-  }; // end Popcorn.youtube.init
+    
+    this.playerId = elementId;
+    this.duration = Number.MAX_VALUE;
+    
+    // The video id for youtube
+    this.vidId = extractIdFromUrl( url );
+    
+    if ( this.vidId ) {
+      this.addEventListener( "load", function() {
+        self.video.cueVideoByUrl( getPlayerAddress( self.vidId ) );
+        cueDelayedDurationCheck.call( self, "playing" );
+      });
+    } else {
+      cueDelayedDurationCheck.call( this, "load" );
+    }
+    
+    registry[elementId] = this;
+    
+    if ( loadedPlayers[elementId] ) {
+      this.dispatchEvent( "load" );
+    }
+  };
+  // end Popcorn.youtube.init
 
   Popcorn.extend( Popcorn.youtube.init.prototype, {
 
       var youcorn = this,
           stateChangeHandler = 'Popcorn.youtube.stateChangeEventHandler',
           errorHandler = 'Popcorn.youtube.errorEventHandler';
+          
       this.video.addEventListener( 'onStateChange', stateChangeHandler );
       this.video.addEventListener( 'onError', errorHandler );
 
        * separately here.
        */
       Popcorn.youtube.stateChangeEventHandler = function( state ) {
-        if ( debug ) {
-          console.log( 'Youtube state updated: ' + state );
-        }
-        if ( state == YOUTUBE_STATE_UNSTARTED ) {
-          youcorn.readyState = READY_STATE_HAVE_METADATA;
-          youcorn.raiseEvent('loadedmetadata');
-        } else if ( state == YOUTUBE_STATE_ENDED ) {
-          youcorn.raiseEvent('ended');
-        } else if ( state == YOUTUBE_STATE_PLAYING ) {
+        // In case ctor has been called many times for many ctors
+        // Only use latest ctor call for each player id        
+        var self = registry[youcorn.playerId];
+        
+        if ( state === YOUTUBE_STATE_UNSTARTED ) {
+          self.readyState = READY_STATE_HAVE_METADATA;
+          self.dispatchEvent( 'loadedmetadata' );
+        } else if ( state === YOUTUBE_STATE_ENDED ) {
+          self.dispatchEvent( 'ended' );
+        } else if ( state === YOUTUBE_STATE_PLAYING ) {
           // Being able to play means current data is loaded.
           if ( !this.loadedData ) {
             this.loadedData = true;
-            youcorn.raiseEvent( 'loadeddata' );
+            self.dispatchEvent( 'loadeddata' );
           }
 
-          youcorn.readyState = READY_STATE_HAVE_CURRENT_DATA;
-          youcorn.raiseEvent( 'playing' );
-        } else if ( state == YOUTUBE_STATE_PAUSED ) {
-          youcorn.raiseEvent( 'pause' );
-        } else if ( state == YOUTUBE_STATE_BUFFERING ) {
-          youcorn.raiseEvent( 'waiting' );
-        } else if ( state == YOUTUBE_STATE_CUED ) {
+          self.readyState = READY_STATE_HAVE_CURRENT_DATA;
+          self.dispatchEvent( 'playing' );
+        } else if ( state === YOUTUBE_STATE_PAUSED ) {
+          self.dispatchEvent( 'pause' );
+        } else if ( state === YOUTUBE_STATE_BUFFERING ) {
+          self.dispatchEvent( 'waiting' );
+        } else if ( state === YOUTUBE_STATE_CUED ) {
           // not handled
         }
       };
 
       Popcorn.youtube.errorEventHandler = function( state ) {
-        if ( debug ) {
-          console.log( 'Youtube error encountered: ' + error );
-        }
-        youcorn.raiseEvent( 'error' );
+        youcorn.dispatchEvent( 'error' );
       };
     },
 
     },
 
     play: function() {
-      this.raiseEvent( 'play' );
+      this.dispatchEvent( 'play' );
       this.video.playVideo();
     },
 
       this.video.playVideo();
       this.video.pauseVideo();
     },
+    
+    currentTime: 0,
+    previousCurrentTime: 0,
 
-    currentTime: function( time ) {
-      if ( time === undef ) {
-        return this.video.getCurrentTime();
-      }
+    seekTo: function( time ) {      
       var playing = this.video.getPlayerState() == YOUTUBE_STATE_PLAYING;
       this.video.seekTo( time, true );
 
       }
 
       // Raise event.
-      this.raiseEvent( 'seeked' );
+      this.dispatchEvent( 'seeked' );
     },
 
     duration: function() {
       return this.video.getDuration();
     },
 
+    // Mute is toggleable
     mute: function() {
-      if ( this.video.getVolume() != 0 ) {
+      if ( this.video.isMuted() ) {
+        this.video.unMute();
+        this.dispatchEvent( 'volumechange' );
+      } else {
         this.video.mute();
-        this.raiseEvent( 'volumechange' );
+        this.dispatchEvent( 'volumechange' );
       }
     },
-
-    volume: function( vol ) {
-      if ( vol == undef ) {
-        return this.video.getVolume() / 100;
-      }
-      if ( vol != this.volume() ) {
-        this.video.setVolume( vol * 100 );
-        this.raiseEvent( 'volumechange' );
-      }
+    
+    volume: 0,
+    previousVolume: 0,
+
+    // Expects beteween 0 and 1
+    setVolume: function( vol ) {
+      this.volume = this.previousVolume = vol;
+      this.video.setVolume( vol * 100 );
+      this.dispatchEvent( 'volumechange' );
     },
 
-    addEventListener: function( eventName, func ) {
-      if ( !this.eventListeners[eventName] ) {
-        this.eventListeners[eventName] = [];
+    addEventListener: function( evt, func ) {
+      var evtName = evt.type || evt;
+      
+      if ( !this.eventListeners[evtName] ) {
+        this.eventListeners[evtName] = [];
       }
-      this.eventListeners[eventName].push( func );
+      
+      this.eventListeners[evtName].push( func );
     },
 
     /**
      * Notify event listeners about an event.
      */
-    raiseEvent: function( name ) {
-      if ( debug ) {
-        console.log( 'Raising event: ' + name );
-      }
-      if ( !this.eventListeners[name] ) {
+    dispatchEvent: function( name ) {
+      var evtName = name.type || name;
+      if ( !this.eventListeners[evtName] ) {
         return;
       }
-      for ( var i in this.eventListeners[name] ) {
-        // @TODO should we mimic the event object sent by HTMLMediaElement?
-        this.eventListeners[name][i].call( this, null );
-      }
+      
+      var self = this;
+      
+      Popcorn.forEach( this.eventListeners[evtName], function( evt ) {
+        evt.call( self, null );
+      });
     },
 
     /* Unsupported methods. */
 
   function startTimeUpdater( youcorn ) {
     youcorn.timeUpdater = setInterval(function() {
+      
       var state = youcorn.video.getPlayerState();
-      if ( (state == YOUTUBE_STATE_ENDED) || (state == YOUTUBE_STATE_PAUSED) ) {
-        clearInterval(youcorn.timeUpdater);
-        return;
+      
+      
+      
+      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 ( youcorn.volume !== youcorn.previousVolume ) {
+        youcorn.setVolume( youcorn.volume );
       }
-      youcorn.raiseEvent( 'timeupdate' );
+      
+      youcorn.dispatchEvent( 'timeupdate' );
     }, timeupdateInterval);
   }
 
   function startProgressUpdater( youcorn ) {
     youcorn.progressUpdater = setInterval(function() {
-      var bytesLoaded = youcorn.video.getVideoBytesLoaded();
-      var bytesToLoad = youcorn.video.getVideoBytesTotal();
-      if ( debug ) {
-        console.log( 'Bytes loaded: ' + bytesLoaded );
-        console.log( 'Bytes to load: ' + bytesToLoad );
-      }
+      var bytesLoaded = youcorn.video.getVideoBytesLoaded(),
+          bytesToLoad = youcorn.video.getVideoBytesTotal();
 
       // 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.raiseEvent( 'loadstart' );
+        youcorn.dispatchEvent( 'loadstart' );
       }
 
       // fully loaded
       if ( bytesLoaded >= bytesToLoad ) {
         youcorn.fullyLoaded = true;
         youcorn.readyState = READY_STATE_HAVE_ENOUGH_DATA;
-        youcorn.raiseEvent( 'canplaythrough' );
+        youcorn.dispatchEvent( 'canplaythrough' );
         clearInterval( youcorn.progressUpdater );
         return;
       }
 
-      youcorn.raiseEvent( 'progress' );
+      youcorn.dispatchEvent( 'progress' );
     }, progressInterval);
   }
 
    * * canplay
    * * seeking
    * * ratechange
-   * * durationchange
    */
 
 })( Popcorn );
index 16e1751ea331bd6d42984f1b53d0969c80bdccac..93d5b1d05e251139797dd3bd9f62736963e5c14e 100644 (file)
@@ -30,7 +30,7 @@
   </p>
   <div>
     <object id="video" type="application/x-shockwave-flash"
-      data="http://www.youtube.com/e/ac7KhViaVqc?enablejsapi=1&amp;version=3"
+      data="http://www.youtube.com/e/ac7KhViaVqc?enablejsapi=1&playerapiid=video&version=3"
       width="250" height="200">
       <param name="allowFullScreen" value="true" />
       <param name="allowscriptaccess" value="always" />
index 7aba180fa5e72ac8b3f0733ae6d9a934d34431ee..29e4b6aca8a90bdd3733c835fc0e80f67ffe3373 100644 (file)
@@ -1,7 +1,9 @@
-var ytReady = false;
-function onYouTubePlayerReady() {
+var ytReady = false,
+    popcorn = Popcorn( Popcorn.youtube( 'video' ) );
+
+popcorn.listen( "load", function onYouTubePlayerReady() {
   ytReady = true;
-}
+});
 
 test( "Popcorn YouTube Plugin Startup", function() {
   var time = 0,
@@ -34,8 +36,7 @@ test( "Popcorn YouTube Plugin Event Tests", function() {
     ok( false, "YouTube did not start." );
     return;
   }
-
-  var popcorn = Popcorn( new Popcorn.youtube( 'video' ) );
+  
   popcorn.volume(1); // is muted later
   
   // check time sync
@@ -59,13 +60,16 @@ test( "Popcorn YouTube Plugin Event Tests", function() {
     'play',
     'playing',
     'seeked',
+    'volumechange',
+    'volumechange',
+    'volumechange',
     'playing',
     'pause',
     'ended'
   ];
 
   var expectedEventCount = expectedEvents.length;
-  expect(expectedEventCount + 2);
+  expect(expectedEventCount + 5);
 
   // register each events
   var eventCount = 0;
@@ -79,7 +83,7 @@ test( "Popcorn YouTube Plugin Event Tests", function() {
         }
       }
       
-      popcorn.listen( event, function() {
+      popcorn.listen( event, function() {        
         eventCount++;
         var expected = expectedEvents.shift();
         if ( expected == event ) {
@@ -92,9 +96,6 @@ test( "Popcorn YouTube Plugin Event Tests", function() {
     })( expectedEvents[i] );
   }
 
-  // begin the test
-  popcorn.play();
-
   // operations set1
   var set1Executed = false;
   popcorn.listen( 'playing', function() {
@@ -105,7 +106,7 @@ test( "Popcorn YouTube Plugin Event Tests", function() {
 
     // toggle volume 1 second after playing
     setTimeout(function() {
-      popcorn.volume(0);
+      popcorn.volume(0.5);
     }, 1000);
 
     // pause 3 seconds after playing
@@ -116,6 +117,9 @@ test( "Popcorn YouTube Plugin Event Tests", function() {
     set1Executed = true;
   });
 
+  // begin the test
+  popcorn.play();
+  
   // operations set2
   var set2Executed = false;
   popcorn.listen( 'pause', function() {
@@ -135,6 +139,25 @@ test( "Popcorn YouTube Plugin Event Tests", function() {
 
     set2Executed = true;
   });
+  
+  // operations set3
+  var set3Executed = false;
+  popcorn.listen( 'seeked', function() {
+    if ( set3Executed ) {
+      return;
+    }
+    
+    popcorn.volume(1);
+    
+    popcorn.mute();
+    equals( popcorn.volume(), 0, "Muted" );
+    
+    popcorn.mute();
+    ok( popcorn.volume() !== 0, "Not Muted" );
+    equals( popcorn.volume(), 1, "Back to volume of 1" );
+
+    set3Executed = true;
+  });
 
   var time = 0,
       wait = 100,
@@ -154,3 +177,37 @@ test( "Popcorn YouTube Plugin Event Tests", function() {
   }, wait );
 });
 
+test( "Popcorn YouTube Plugin Url and Duration Tests", function() {
+  function plus(){ 
+    if ( ++count == expects ) {
+      start(); 
+    }
+  }
+  
+  QUnit.reset();
+  
+  var count = 0,
+      expects = 4,
+      rawTube = Popcorn.youtube( 'video', 'http://www.youtube.com/watch?v=9oar9glUCL0' );
+      
+  expect( expects );
+  stop( 5000 );
+  
+  equals( rawTube.vidId, '9oar9glUCL0', 'Video id set' );
+  plus();
+  
+  equals( rawTube.duration, Number.MAX_VALUE, 'Duration starts as Max Value');
+  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" );
+    plus();
+    
+    rawTube.pause();
+  });
+  
+  rawTube.play();
+  
+});
\ No newline at end of file
index 64215bc3dcaa4b701d75c85f6b23686b5bb42965..24ba6c76e59ba41ac39d951584a4adea0d79f091 100644 (file)
         return;
       }
 
-      if ( (typeof entity) == "string" ) {
-        matches = rIdExp.exec( entity );
+      // check if entity is a valid string id
+      matches = rIdExp.exec( entity );
 
-        if ( matches.length && matches[2]  ) {
-          elem = document.getElementById(matches[2]);
-        }
+      // get video element by id or reference
+      this.video = matches && matches.length && matches[ 2 ] ?
+                    document.getElementById( matches[ 2 ] ) :
+                    entity;
 
-        this.video = elem ? elem : null;
-      } else if ( entity instanceof Object ) {
-        this.video = entity;
-      }
+      Popcorn.addInstance( this );
 
       this.data = {
         history: [],
           // this is so we do not fall off either end
 
           var duration = that.video.duration;
-          
-          if( typeof that.video.duration === "function") {
-            duration = that.video.duration();
-          }
-          
           // Check for no duration info (NaN)
           var videoDurationPlus = duration != duration ? Number.MAX_VALUE : duration + 1;
 
                 tracksByEnd    = tracks.byEnd,
                 tracksByStart  = tracks.byStart;
 
-
-            if (typeof this.currentTime === "function") {
-              currentTime = this.currentTime();
-            }
-
             // Playbar advancing
             if ( previousTime < currentTime ) {
 
         }
       };
 
-      if ( this.video ) {
-        isReady( this );
-      }
+      isReady( this );
 
       return this;
     }
 
       // todo: play, pause, mute should toggle
       var methods = "load play pause currentTime playbackRate mute volume duration",
-          noArgMethods = /load|play|pause|mute/,
           ret = {};
 
 
 
         ret[ name ] = function( arg ) {
 
-          var isFunc = typeof this.video[name] === "function";
-
-          if ( noArgMethods.test( name ) || ( arg !== false && arg !== null && typeof arg !== "undefined" ) ) {
-
-            if ( isFunc ) {
-              this.video[ name ]( arg );
-            } else {
-              this.video[ name ] = arg;
-            }
+          if ( typeof this.video[name] === "function" ) {
+            this.video[ name ]();
 
             return this;
           }
 
-          if ( isFunc ) {
-            return this.video[ name ]();
+
+          if ( arg !== false && arg !== null && typeof arg !== "undefined" ) {
+
+            this.video[ name ] = arg;
+
+            return this;
           }
 
           return this.video[ name ];
   }, false );
 
 })(window, window.document);
-
index 574b6e63792edd918c84494d89446917bcedd133..32294c6fadc44643235b345328e61c83c63104ba 100755 (executable)
@@ -375,82 +375,6 @@ test("Stored By Type", function () {
 });
 
 
-test("Passed an object", function () {
-  
-  QUnit.reset();
-  
-  var evtMethods = "addEventListener dispatchEvent".split(/\s+/),
-      methods = "load play pause currentTime playbackRate mute volume duration".split(/\s+/),
-      attributes = "readyState autoplay".split(/\s+/),
-      obj = {},
-      p,
-      playEvent,
-      count = 0,
-      wants;
-
-  function plus(){ 
-
-    if ( ++count === wants ) {  
-      start();
-    } 
-  }
-  
-  Popcorn.forEach( methods, function( method ) {
-    obj[method] = (function() {
-      var calledWithArgs = 0,
-          calledWithoutArgs = 0;
-          
-      return function( arg ) {
-        if ( arg && !calledWithArgs ) {
-          calledWithArgs = 1;
-          ok(true, method+" called with argument");
-          plus();
-        } else if ( !arg && !calledWithoutArgs ) {
-          calledWithoutArgs = 1;
-          ok(true, method+" called without argument");
-          plus();
-        }
-      }
-    })();
-  });
-  
-  Popcorn.forEach( evtMethods, function( method ) {
-    obj[method] = (function() {
-      var hasCalled = 0;
-      
-      return function() {
-        if ( hasCalled ) {
-          return;
-        }
-        
-        hasCalled = 1;
-        ok(true, method+" called");
-        plus();
-      };
-    })()
-  });
-  
-  Popcorn.forEach( attributes, function( attr ) {
-    obj[attr] = 3;
-  });
-  
-  p = Popcorn( obj );
-  wants = methods.length*2 + evtMethods.length;
-
-  expect( wants );
-  stop( 10000 );
-  
-  p.listen( "play", Popcorn.nop );
-  
-  Popcorn.forEach( methods, function( method ) {
-    p[method]();
-    p[method]( 1 );
-  });
-  
-  p.trigger( "play" );
-});
-
-
 test("Simulated", function () {
   
   QUnit.reset();