]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
initial commit of the js and example file
authorKarim Hamidou <khamidou@gmail.com>
Fri, 30 Sep 2011 15:05:08 +0000 (17:05 +0200)
committerKarim Hamidou <khamidou@gmail.com>
Fri, 30 Sep 2011 15:05:08 +0000 (17:05 +0200)
plugins/mediafragment/popcorn.mediafragment.html [new file with mode: 0644]
plugins/mediafragment/popcorn.mediafragment.js [new file with mode: 0644]

diff --git a/plugins/mediafragment/popcorn.mediafragment.html b/plugins/mediafragment/popcorn.mediafragment.html
new file mode 100644 (file)
index 0000000..33a1da8
--- /dev/null
@@ -0,0 +1,44 @@
+<!DOCTYPE html>
+<html>
+<head>
+  <title>Popcorn footnote Plug-in Demo</title>
+
+  <script src="../../popcorn.js"></script>
+  <script src="popcorn.mediafragment.js"></script>
+  <script>
+    document.addEventListener('DOMContentLoaded', function () {
+      var p = Popcorn( "#video" ).mediafragment({start: 0}).play()   
+
+         document.getElementById("pauseButton").addEventListener( 'click', function() {
+               p.pause()
+               });
+               
+    }, false);
+
+  </script>
+</head>
+<body>
+  <h1 id="qunit-header">Popcorn Mediafragment Plug-in Demo</h1>
+  <p> Clicking the pause button should update the location hash.</p>
+  <p> Copypasting the changed url in a browser bar should take you to the exact instant in the video.</p>
+  <div>
+    <video id="video"
+      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>
+  </div>
+  <button id="pauseButton">Pause</button>
+</body>
+</html>
diff --git a/plugins/mediafragment/popcorn.mediafragment.js b/plugins/mediafragment/popcorn.mediafragment.js
new file mode 100644 (file)
index 0000000..0f01e63
--- /dev/null
@@ -0,0 +1,52 @@
+// PLUGIN: Mediafragment
+
+(function ( Popcorn ) {
+
+  /**
+   * Mediafragment popcorn plug-in
+   * Adds (limited) support for mediafragment requests 
+   * to a popcorn video.  
+   * @param {Object} options
+   *
+  **/
+    Popcorn.plugin( "mediafragment" , {
+
+      manifest: {
+        about: {
+          name: "Popcorn mediafragment plugin",
+          version: "0.1",
+          author: "Karim Hamidou",
+          website: "http://neyret.fr/~karim"
+        },
+        options: {
+        }
+      },
+      
+    _setup: function( options ) {
+        var advanceTime = function() {
+              var url = window.location.href;
+              
+              if ( url.split("#")[1] != null ) {
+                  pageoffset = url.split( "#" )[1];                                                    
+                  
+                  if ( pageoffset.substring( 2 ) != null ) {
+                    var offsettime = pageoffset.substring( 2 );                                                
+                    this.currentTime(parseFloat(offsettime));
+                  }                                                    
+              }
+        }
+        
+        
+        this.listen( 'loadedmetadata', advanceTime );        
+        this.listen("pause", function(data) {            
+            splitArr = window.location.href.split("#")                 
+            history.replaceState({}, "", splitArr[0] + "#t=" + this.currentTime().toFixed(2));
+        });
+        
+    },
+
+    _teardown: function( options ) {
+      // FIXME: anything to implement here ?
+    }
+  });
+})( Popcorn );