]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
[#140] Demos added, delayed events. TO DO: Fix test duration bug, mute toggle bug...
authorstevenaw <sweerdenburg@gmail.com>
Wed, 16 Mar 2011 23:03:50 +0000 (19:03 -0400)
committerstevenaw <sweerdenburg@gmail.com>
Wed, 16 Mar 2011 23:03:50 +0000 (19:03 -0400)
players/youtube/popcorn.youtube.html
players/youtube/popcorn.youtube.js

index 3b3b5db227d089f7d09828c2f44eb749dad56e06..5616d8fb3f22f36119392f3ecf630627ffcb19d6 100644 (file)
@@ -5,6 +5,13 @@
       <script src="../../popcorn.js"></script>
       <script type="text/javascript" src="popcorn.youtube.js"></script>
       <script src="../../plugins/footnote/popcorn.footnote.js"></script>
+      <script src="../../plugins/flickr/popcorn.flickr.js"></script>
+      <script src="../../plugins/attribution/popcorn.attribution.js"></script>
+      <script src="../../plugins/webpage/popcorn.webpage.js"></script>
+      <script src="../../plugins/googlefeed/popcorn.googlefeed.js"></script>
+      <script src="../../plugins/image/popcorn.image.js"></script>
+      <script src="../../plugins/subtitle/popcorn.subtitle.js"></script>
+      <script src="../../plugins/twitter/popcorn.twitter.js"></script>
       <script>
         // Helper function to get elements
         function element(id) {
         }
         
         document.addEventListener( 'DOMContentLoaded', function() {
-          var popcorn = Popcorn( Popcorn.youtube( 'video', 'http://www.youtube.com/watch?v=9oar9glUCL0' ) ),
-              paused = true;
+          var paused = true,
+              popcorn;
           
-          popcorn = popcorn.footnote({
-            start: 5, // seconds
-            end: 40, // seconds
-            text: 'The video is "RiP: A Remix Manifesto", by Brett Gaylor',
-            target: 'footnotediv'
-          })
+          popcorn = Popcorn( Popcorn.youtube( 'video', 'http://www.youtube.com/watch?v=9oar9glUCL0' ) )
+                    .footnote({
+                      start: 5, // seconds
+                      end: 40, // seconds
+                      text: 'The video is "RiP: A Remix Manifesto", by Brett Gaylor',
+                      target: 'footnotediv'
+                    })
+                    .flickr({
+                      start: 20, // seconds
+                      end: 40, // seconds
+                      tags: 'georgia',
+                      numberofimages: '8',
+                      target: 'flickrdiv'
+                    })
+                    .twitter({
+                      start: 20, // seconds
+                      end: 45, // seconds
+                      title: 'Oil Spill',
+                      src: '#oilspill',
+                      target: 'twitterdiv'
+                    })
+                    .attribution({
+                      start: 5, // seconds
+                      end: 60, // seconds
+                      nameofwork: "Internet",
+                      nameofworkurl:"http://www.archive.org/details/CC1232_internet",
+                      copyrightholder:"The Computer Chronicles",
+                      license:"CC-BY-NC-ND",
+                      licenseurl: "http://creativecommons.org/licenses/by-nc-nd/2.0/",
+                      target: 'attribdiv'
+                    })
+                    .subtitle({
+                      start: 5, // seconds
+                      end: 15, // seconds
+                      text: 'This is overlaid on top of the video. You can hightlight it!',
+                      display: 'inline',
+                      language: "en"
+                    })
+                    .webpage({
+                      id: "webpages-a", 
+                      start: 0, // seconds
+                      end: 15, // seconds
+                      src: 'http://webmademovies.org/',
+                      target: 'webpagediv'
+                    })
+                    .googlefeed({
+                        start: 0, // seconds
+                        end: 15, // seconds
+                        target: "feeddiv",
+                        url: "http://zenit.senecac.on.ca/~chris.tyler/planet/rss20.xml",
+                        title: "Planet Feed",
+                        orientation: "Vertical"
+                    })
+                    .image({
+                      start: 5, // seconds
+                      end: 15, // seconds
+                      href: 'http://www.drumbeat.org/',
+                      src: 'https://www.drumbeat.org/media//images/drumbeat-logo-splash.png',
+                      target: 'imagediv'
+                    })
           .listen( 'durationchange', function() {
             element( 'player-duration' ).innerHTML = popcorn.duration();
           })
@@ -38,7 +99,9 @@
           .listen('pause', function() {
             paused = true;
             element( 'btn-play-pause' ).innerHTML = 'Play';
-          });
+          })
+          .mute()
+          .play();
             
           // Setup UI after loaded
           popcorn.listen( 'load', function() {
   </head>
   <body>
     <div>
-       <div style="float:right;">
+      <div>
+        <div id="video" width="360" height="300" ></div>
+        <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>
+            <li>Current Time (s): <span id="player-time"></span></li>
+            <li>Volume (0-1): <span id="player_vol"></span></li>
+            <li>Video Duration (s): <span id="player-duration"></span></li>
+          </ul>
+        </div>
+      </div>
+      <div>
         <h3>Description</h3>
         <p>
           This demo will showcase how a Youtube flash video can be integrated into Popcorn. This  is done by making the flash video masquerade as HTML 5 video.<br />
           Due to the Flash security model, this demo must be  run from a web server<br />
           From 5 to 40 seconds, the footnote 'The video is "RiP: A Remix Manifesto", by Brett Gaylor' will appear below 'Footnote Area'.
         <hr >
-          Youtube does not support their player to be chromeless (hidden controls), but custsom controls have been developed and tied into their player.<br />
-          Clicking play/pause or seeking in either the video or via custsom controls will cause the other to update.<br />
-          Clicking on the embed option in the Vimeo player while the video is playing will cause the video to pause and custom controls to update.<br />
-          The video can be specified in the HTML source by giving the vimeo web site url (http://www.youtube.com/watch?v=VIDEOID) to either Popcorn.youtube or as the div src attribute.<br/>
+          Youtube does support their player to be chromeless (hidden controls), but their controls are left in to provide richer interaction.<br />
+          Custom controls have been developed and tied into their player for this demo.<br />
+          Clicking play/pause or seeking in either the video or via custom controls will cause the other to update.<br />
+          The video can be specified in the HTML source by giving the youtube web site url (http://www.youtube.com/watch?v=VIDEOID) to either Popcorn.youtube or as the div src attribute.<br/>
         </p>
-        <br />
-        <br />
-        <br />
-        <div id="footnotediv" width="50%" height="50%">
-          <strong>Footnote Area</strong><br />
-        </div>
-      </div>
-      <div id="video" width="360" height="300" ></div>
-      <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>
+        <h4>Expected Events</h4>
         <ul>
-          <li>Status: <span id="player-status">Not Ready</span></li>
-          <li>Current Time (s): <span id="player-time"></span></li>
-          <li>Volume (0-1): <span id="player_vol"></span></li>
-          <li>Video Duration (s): <span id="player-duration"></span></li>
+          <li>From 5 to 40 seconds, the footnote 'The video is "RiP: A Remix Manifesto", by Brett Gaylor' will appear below 'Footnote Area'.</li>
+          <li>From 20 to 40 seconds, the a flickr stream of 8 images  tagged 'georgia' will appear below 'Flickr Area'.</li>
+          <li>From 20 to 45 seconds, tweets tagged #oilspill will appear below 'Twitter Area'.</li>
+          <li>From 5 to 60 seconds, the Creative Commons license will appear below 'Attributions Area'.</li>
+          <li>From 5 to 15 seconds, the Mozilla Drumbeat logo will appear below 'Image Area'.</li>
+          <li>From 5 to 15 seconds, the subtitle 'This is overlaid on top of the video. You can hightlight it!' will appear in front of the video.</li>
+          <li>From 0 to 20 seconds, blogs from 'http://zenit.senecac.on.ca/~chris.tyler/planet/rss20.xml' will appear below 'Google Feed Area'.</li>
+          <li>From 0 to 15 seconds, the site 'http://webmademovies.org/' will appear below 'Web Page Area'.</li>
         </ul>
       </div>
+      <div id="footnotediv" width="50%" height="50%">
+        <strong>Footnote Area</strong><br />
+      </div>
+      <div id="attribdiv" width="50%" height="50%">
+        <strong>Attributions Area</strong><br />
+      </div>
+      <div id="flickrdiv" width="50%" height="50%">
+        <strong>Flickr Area</strong><br />
+      </div>
+      <div id="twitterdiv" width="50%" height="50%">
+        <strong>Twitter Area</strong><br />
+      </div>
+      <div id="imagediv" width="50%" height="50%">
+        <strong>Image Area</strong><br />
+      </div>
+      <div id="feeddiv" width="50%" height="50%">
+        <strong>Google Feed Area</strong><br />
+      </div>
+      <div id="webpagediv" width="100px" height="50px">
+        <strong>Web Page Area</strong><br />
+      </div>
     </div>
   </body>
 </html>
index 192c46f07ab7437e689e89f5fc49c5b6575fadb5..61beeec30757d5e715cbc0f9e228915b5b7d4bc4 100644 (file)
@@ -102,6 +102,7 @@ var onYouTubePlayerReady;
         width="250" height="200">
         <param name="allowFullScreen" value="true" />
         <param name="allowscriptaccess" value="always" />
+        <param name="wmode" value="transparent" />
       </object>*/
   
   function createSWFObject( params ) {
@@ -121,8 +122,14 @@ var onYouTubePlayerReady;
     param2.setAttribute( "name", "allowscriptaccess" );
     param2.setAttribute( "value", "always" );
     
+    // This param allows us to place html on top of the Flash video
+    var param3 = document.createElement( "param" );
+    param3.setAttribute( "name", "wmode" );
+    param3.setAttribute( "value", "transparent" );
+    
     obj.appendChild( param1 );
     obj.appendChild( param2 );
+    obj.appendChild( param3 );
     
     return obj;
   }
@@ -154,6 +161,24 @@ var onYouTubePlayerReady;
     // Issue load event
     vid.dispatchEvent( 'load' );
   }
+  
+  function makeFlashObject( container ) {
+    this.video = createSWFObject({
+      playerId: this.playerId,
+      videoId: this.vidId,
+      width: container.getAttribute("width") || 460,
+      height: container.getAttribute("height") || 350
+    });
+    
+    container.appendChild( this.video );
+    
+    // For calculating position relative to video (like subtitles)
+    this.offsetWidth = this.video.offsetWidth;
+    this.offsetHeight = this.video.offsetHeight;
+    this.offsetParent = this.video.offsetParent;
+    this.offsetLeft = this.video.offsetLeft;
+    this.offsetTop = this.video.offsetTop;
+  }
 
   Popcorn.youtube = function( elementId, url ) {
     return new Popcorn.youtube.init( elementId, url );
@@ -203,14 +228,7 @@ var onYouTubePlayerReady;
       if ( container.children.length ) {
         this.video = container.firstChild;
       } else {
-        this.video = createSWFObject({
-          playerId: this.playerId,
-          videoId: this.vidId,
-          width: container.getAttribute("width") || 460,
-          height: container.getAttribute("height") || 350
-        });
-        
-        container.appendChild( this.video );
+        makeFlashObject.call( this, container );
       }
     } else {
       document.addEventListener( "DOMContentLoaded", function() {
@@ -226,14 +244,7 @@ var onYouTubePlayerReady;
           throw "Could not find video id";
         }
         
-        self.video = createSWFObject({
-          playerId: self.playerId,
-          videoId: self.vidId,
-          width: container.getAttribute("width") || 460,
-          height: container.getAttribute("height") || 350
-        });
-        
-        container.appendChild( self.video );
+        makeFlashObject.call( self, container );
       }, false);
     }
     
@@ -313,16 +324,34 @@ var onYouTubePlayerReady;
     },
 
     play: function() {
+      // In case called before video is loaded, defer acting
+      if ( !loadedPlayers[this.playerId] ) {
+        this.addEventListener( "load", this.play );
+        return;
+      }
+      
       this.dispatchEvent( 'play' );
       this.video.playVideo();
     },
 
     pause: function() {
+      // In case called before video is loaded, defer acting
+      if ( !loadedPlayers[this.playerId] ) {
+        this.addEventListener( "load", this.pause );
+        return;
+      }
+      
       this.video.pauseVideo();
       // pause event is raised by Youtube.
     },
 
     load: function() {
+      // In case called before video is loaded, defer acting
+      if ( !loadedPlayers[this.playerId] ) {
+        this.addEventListener( "load", this.load );
+        return;
+      }
+      
       this.video.playVideo();
       this.video.pauseVideo();
     },
@@ -345,12 +374,14 @@ var onYouTubePlayerReady;
       this.dispatchEvent( 'seeked' );
     },
 
-    duration: function() {
-      return this.video.getDuration();
-    },
-
     // Mute is toggleable
     mute: function() {
+      // In case called before video is loaded, defer acting
+      if ( !loadedPlayers[this.playerId] ) {
+        this.addEventListener( "load", this.mute );
+        return;
+      }
+      
       if ( this.volume !== 0 ) {
         this.preMuteVol = this.volume;        
         this.setVolume( 0 );