]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
[#t644] fixed subtitle bug in multiple instance and tests
authorScottDowne <sdowne@learn.senecac.on.ca>
Wed, 6 Jul 2011 19:28:01 +0000 (15:28 -0400)
committerScottDowne <sdowne@learn.senecac.on.ca>
Wed, 6 Jul 2011 19:28:01 +0000 (15:28 -0400)
plugins/subtitle/popcorn.subtitle.js
plugins/subtitle/popcorn.subtitle.unit.html
plugins/subtitle/popcorn.subtitle.unit.js

index db24f5d2a42190409906ac6acc52e27032af5d81..bb3235f0741094f72e51496f82988ce53711b797 100755 (executable)
         }
       },
       createDefaultContainer = function( context ) {
-        
-        // clear this function from future calls; we are done
-        createDefaultContainer = Popcorn.nop;
+
+        var ctxContainer = context.container = document.createElement( "div" ),
+            style = ctxContainer.style,
+            media = context.media;
 
         var updatePosition = function() {
           var position = context.position();
           setTimeout( updatePosition, 10 );
         };
 
-        var ctxContainer = context.container = document.createElement( "div" ),
-            style = ctxContainer.style,
-            media = context.media;
-
-        ctxContainer.id = "subtitlediv";
+        ctxContainer.id = Popcorn.guid();
         style.position = "absolute";
         style.color = "white";
         style.textShadow = "black 2px 2px 6px";
         i++;
 
         // Creates a div for all subtitles to use
-        ( !this.container && !options.target || options.target === "subtitle-container" ) && 
+        ( !this.container && ( !options.target || options.target === "subtitle-container" ) ) && 
           createDefaultContainer( this );
 
         // if a target is specified, use that
           // use shared default container
           options.container = this.container;
         }
-        
+
         document.getElementById( options.container.id ).appendChild( newdiv );
         options.innerContainer = newdiv;
 
index 1a02e3ebee9bbdc653ac6ba81071a67c3b6c7496..05ff6db2196ee51586afc48e880080dc2fa26f6f 100755 (executable)
 
     <p>Your user agent does not support the HTML5 Video element.</p> 
 
+  </video>
+  <video id='video2' 
+    controls preload='none' 
+    width= '250px'
+    poster="../../test/poster.png"> 
+
+    <source id='mp4'
+      src="../../test/trailer.mp4"
+      type='video/mp4; codecs="avc1, mp4a"'> 
+
+    <source id='ogv'
+      src="../../test/trailer.ogv"
+      type='video/ogg; codecs="theora, vorbis"'> 
+
+    <p>Your user agent does not support the HTML5 Video element.</p> 
+
   </video> 
   <h2>Choose your language</h2>
   <select id="language">
index 5639d069b408e10fd9bca0fea195f14fabf8c43f..aa3e2348c0cb1aa9e92646d1eddcc8ba74731d9c 100755 (executable)
@@ -1,11 +1,13 @@
 test("Popcorn Subtitle Plugin", function () {
  
   var popped = Popcorn( "#video" ),
-      expects = 14,
+      popped2 = Popcorn( "#video2" ),
+      expects = 16,
       count = 0,
       subTop = 9001,
       subLeft = 9001,
-      subtitlediv;
+      subtitlediv,
+      subtitle2div;
  
   expect(expects);
  
@@ -15,30 +17,30 @@ test("Popcorn Subtitle Plugin", function () {
     }
   }
  
-  stop();
+  stop( 12000 );
    
   ok ( 'subtitle' in popped, "subtitle is a method of the popped instance" );
   plus();
  
   popped.subtitle({
       start: 0,
-      end: 1,
+      end: 2,
       text: 'this is the first subtitle of 2011',
       language: "en",
       languagesrc: "language",
       accessibilitysrc: "accessibility"
     } )
   .subtitle({
-      start: 1,
-      end: 2,
+      start: 2,
+      end: 4,
       text: 'this is the second subtitle of 2011',
       language: "en",
       languagesrc: "language",
       accessibilitysrc: "accessibility"
     } )
   .subtitle({
-      start: 3,
-      end: 4,
+      start: 5,
+      end: 7,
       text: 'this is the third subtitle of 2011',
       language: "en",
       languagesrc: "language",
@@ -46,10 +48,26 @@ test("Popcorn Subtitle Plugin", function () {
     } )
     .volume(0)
     .play();
- 
-  subtitlediv = document.getElementById( 'subtitlediv' );
 
-  popped.exec( 0.5, function() {
+  subtitlediv = popped.getTrackEvent( popped.getLastTrackEventId() ).container;
+
+  popped.subtitle({
+    start: 7,
+    end: 9,
+    text: 'instance one test'
+  });
+
+  popped2.subtitle({
+      start: 7,
+      end: 9,
+      text: 'instance two test'
+    })
+    .volume(0)
+    .play().pause();
+
+  subtitle2div = popped2.getTrackEvent( popped2.getLastTrackEventId() ).container;
+
+  popped.exec( 1, function() {
    
     popped.media.pause();
     equals( subtitlediv.children[ 0 ].innerHTML, "this is the first subtitle of 2011", "subtitle displaying correct information" );
@@ -70,7 +88,7 @@ test("Popcorn Subtitle Plugin", function () {
    
   });
  
-  popped.exec( 1.5, function() {
+  popped.exec( 3, function() {
  
     popped.media.pause();
 
@@ -97,7 +115,7 @@ test("Popcorn Subtitle Plugin", function () {
    
   });
  
-  popped.exec( 2.5, function() {
+  popped.exec( 4, function() {
    
     popped.media.pause();
     equals (subtitlediv.children[ 1 ].innerHTML, "", "subtitle is clear" );
@@ -107,7 +125,7 @@ test("Popcorn Subtitle Plugin", function () {
  
   });
  
-  popped.exec( 3.5, function() {
+  popped.exec( 6, function() {
 
     popped.media.play();
 
@@ -132,7 +150,23 @@ test("Popcorn Subtitle Plugin", function () {
    
   });
 
-  popped.exec( 5, function() {
+  popped.exec( 8, function() {
+    popped.pause();
+    popped2.currentTime( 8 );
+  });
+
+  popped2.exec( 8, function() {
+    popped2.media.pause();
+
+    equals (subtitlediv.children[ 3 ].innerHTML, "instance one test", "subtitle displaying correct information" );
+    plus();
+    equals (subtitle2div.children[ 0 ].innerHTML, "instance two test", "subtitle displaying correct information" );
+    plus();
+
+    popped.media.play();
+  });
+
+  popped.exec( 10, function() {
     ok ( document.getElementById( 'subtitle-0' ).style.display === "none" && 
         document.getElementById( 'subtitle-1' ).style.display === "none" &&
         document.getElementById( 'subtitle-2' ).style.display === "none", "All subtitles are no longer visible" );