added and activated the mediafragment plugin? popcorn-port
authorhamidouk
Wed, 09 Nov 2011 14:49:20 +0100
branchpopcorn-port
changeset 216 d1e891627286
parent 215 e03f5f886f52
child 217 ec3e6d34462c
added and activated the mediafragment plugin?
sbin/build/client.xml
src/js/init.js
src/js/libs/popcorn.mediafragment.js
--- a/sbin/build/client.xml	Wed Nov 09 14:46:27 2011 +0100
+++ b/sbin/build/client.xml	Wed Nov 09 14:49:20 2011 +0100
@@ -70,7 +70,7 @@
 	<target name="concatenate" description="Build the developer release file" depends="make_templates">
 	    <concat encoding="UTF-8" outputencoding="UTF-8" destfile="../../build/LdtPlayer-release.js">
 			<filelist dir="../../src/js/" files="header.js" />
-	        <filelist dir="../../src/js/libs" files="popcorn.js popcorn.youtube.js popcorn.code.js popcorn.jwplayer.js jwplayer.js mustache.js raphael.js" />
+	        <filelist dir="../../src/js/libs" files="popcorn.js popcorn.youtube.js popcorn.code.js popcorn.jwplayer.js popcorn.mediafragment.js jwplayer.js mustache.js raphael.js" />
 	        <filelist dir="../../src/js" files="LdtPlayer.js" />
 	    	<filelist dir="../../build" files="compiled_templates.js" />
 	    	<filelist dir="../../src/js" files="utils.js data.js site.js ui.js widgets.js layout.js init.js" />
--- a/src/js/init.js	Wed Nov 09 14:46:27 2011 +0100
+++ b/src/js/init.js	Wed Nov 09 14:49:20 2011 +0100
@@ -15,13 +15,13 @@
       case "html5":
            var tmpId = Popcorn.guid("video"); 
            IriSP.jQuery("#" + containerDiv).append("<video src='" + options.file + "' id='" + tmpId + "'></video>");
-           pop = Popcorn("#" + tmpId);
+           pop = Popcorn("#" + tmpId).mediafragment({start : 0});
         break;
         
       case "jwplayer":
           var opts = IriSP.jQuery.extend({}, options);
           delete opts.container;
-          pop = Popcorn.jwplayer("#" + containerDiv, "", opts);
+          pop = Popcorn.jwplayer("#" + containerDiv, "", opts).mediafragment({start : 0});
         break;
       
       case "youtube":
@@ -34,7 +34,7 @@
           // Popcorn.youtube wants us to specify the size of the player in the style attribute of its container div.
           IriSP.jQuery("#" + containerDiv).attr("style", str);
           
-          pop = Popcorn.youtube("#" + containerDiv, opts.video, opts);
+          pop = Popcorn.youtube("#" + containerDiv, opts.video, opts).mediafragment({start : 0});
         break;
         
       default:
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/js/libs/popcorn.mediafragment.js	Wed Nov 09 14:49:20 2011 +0100
@@ -0,0 +1,54 @@
+// 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));
+                  }							
+              }
+        }
+        
+        var updateTime = function() {
+            splitArr = window.location.href.split("#")			
+            history.replaceState({}, "", splitArr[0] + "#t=" + this.currentTime().toFixed(2));
+        };
+        
+        this.listen( 'loadedmetadata', advanceTime );        
+        this.listen("pause", updateTime);
+        this.listen("seeked", updateTime);
+        
+    },
+
+    _teardown: function( options ) {
+      // FIXME: anything to implement here ?
+    }
+  });
+})( Popcorn );