]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
[#649] Trigger canplayall if readyState permits
authorRick Waldron <waldron.rick@gmail.com>
Wed, 20 Jul 2011 21:52:33 +0000 (17:52 -0400)
committerRick Waldron <waldron.rick@gmail.com>
Wed, 20 Jul 2011 21:52:33 +0000 (17:52 -0400)
popcorn.js
test/popcorn.unit.js

index f7a6b6d4d1ca9c16ab18969fe954a101c5840121..c1e76ecb1f4ea56fb0a0f050fe588e74ad3e7e71 100644 (file)
 
           // Execute hook add method if defined
           if ( eventHook.add ) {
-            eventHook.add.call( this );
+            eventHook.add.call( this, {}, fn );
           }
 
           // Reassign event type to our piggyback event type if defined
     hooks: {
       canplayall: {
         bind: "canplaythrough",
-        add: function() {
+        add: function( event, callback ) {
+
+          var state = false;
+
+          if ( this.media.readyState ) {
+
+            callback.call( this, event );
+
+            state = true;
+          }
+
           this.data.hooks.canplayall = {
-            fired: false
+            fired: state
           };
         },
         // declare special handling instructions
index 570e76f1f06ce8b312264d53782351a262b80bb1..54bc3eae189710f57ad5d7f464d877accee9a8d5 100644 (file)
@@ -682,6 +682,39 @@ test("Popcorn.events.hooks: canplayall", function() {
   });
 });
 
+test("Popcorn.events.hooks: canplayall fires immediately if ready", function() {
+  //qunit-fixture
+
+  var $pop = Popcorn("#video"),
+    expects = 1,
+    count = 0,
+    fired = 0;
+
+  expect(expects);
+
+  function plus(){
+    if ( ++count == expects ) {
+      start();
+    }
+  }
+
+  stop( 20000 );
+
+  function poll() {
+    if ( $pop.media.readyState >= 2 ) {
+      // this should trigger immediately
+      $pop.listen("canplayall", function( event ) {
+        equal( ++fired, 1, "canplayall is fired immediately if readyState permits" );
+        plus();
+      });
+    } else {
+      setTimeout( poll, 10 );
+    }
+  }
+
+  poll();
+});
+
 /*
 <video height="180" width="300" id="video" controls>
 <source src="http://videos.mozilla.org/serv/webmademovies/popcornplug.mp4"></source>