Fusion avec embed-playerapi-rewrite. Added new player api to the mainline. popcorn-port
authorhamidouk
Wed, 25 Jan 2012 15:38:46 +0100
branchpopcorn-port
changeset 709 05ae2aa10d24
parent 698 329333e07267 (current diff)
parent 708 a4ae99d593e0 (diff)
child 710 ea5f2fa37edb
Fusion avec embed-playerapi-rewrite. Added new player api to the mainline.
--- a/sbin/build/client.xml	Mon Jan 23 17:27:37 2012 +0100
+++ b/sbin/build/client.xml	Wed Jan 25 15:38:46 2012 +0100
@@ -59,7 +59,7 @@
     	<filelist dir="../../build" files="compiled_templates.js" />
       
       <!-- core files -->
-    	<filelist dir="../../src/js" files="pop.js utils.js data.js site.js ui.js widgets.js modules.js layout.js init.js" />
+    	<filelist dir="../../src/js" files="utils.js pop.js data.js site.js ui.js widgets.js modules.js layout.js init.js" />
 
       <!-- modules -->
 			<fileset dir="../../src/js/modules" casesensitive="yes">
--- a/src/js/init.js	Mon Jan 23 17:27:37 2012 +0100
+++ b/src/js/init.js	Wed Jan 25 15:38:46 2012 +0100
@@ -47,14 +47,15 @@
           delete opts.container;
           delete opts.type;
 
-          if (options.provider === "rtmp") {
+          
+          /* Try to guess options.file and options.streamer only if file and streamer
+             are not already defined in the configuration */
+          if (options.provider === "rtmp" && !opts.hasOwnProperty("file") && !opts.hasOwnProperty("streamer")) {
             /* exit if we can't access the metadata */
             if (typeof(IriSP.__jsonMetadata) === "undefined") {
                 break;
             };
 
-
-             
             // the json format is totally illogical
             //opts.streamer = IriSP.__jsonMetadata["medias"][0]["meta"]["item"]["value"];
             //var source = IriSP.__jsonMetadata["medias"][0]["href"];
@@ -81,8 +82,7 @@
                  if (i < pathSplit.length - 1)
                   opts.file += "/";
               }
-            }
-
+            }            
           } else {
             /* other providers type, video for instance -
                pass everything as is */
@@ -96,7 +96,7 @@
             opts["controlbar.position"] = "none";
           }
 
-          pop = IriSP.PopcornReplacement.jwplayer("#" + containerDiv, opts);
+          pop = new IriSP.PopcornReplacement.jwplayer("#" + containerDiv, opts);
         break;
       
       case "youtube":
@@ -112,6 +112,11 @@
           pop = Popcorn.youtube("#" + containerDiv, opts.video, opts);
         break;
         
+      case "allocine":
+          /* pass the options as-is to the allocine player and let it handle everything */
+          pop = new IriSP.PopcornReplacement.allocine("#" + containerDiv, options);
+          break;
+          
       default:
         pop = undefined;
     };
--- a/src/js/pop.js	Mon Jan 23 17:27:37 2012 +0100
+++ b/src/js/pop.js	Wed Jan 25 15:38:46 2012 +0100
@@ -1,31 +1,47 @@
 /* wrapper that simulates popcorn.js because
    popcorn is a bit unstable at the time */
 
-IriSP.PopcornReplacement = {
-  msgPump : {} /* used by jquery to receive and send messages */,
-  __delay_seek_signal : false
-};
-
-IriSP.PopcornReplacement.media = { 
-  "paused": true,
-  "muted": false
+IriSP.PopcornReplacement = {  
 };
 
-IriSP.PopcornReplacement.listen = function(msg, callback) {
-//  IriSP.jQuery(IriSP.PopcornReplacement.msgPump).bind(msg, function(event, rest) { callback(rest); });
-  if (!IriSP.PopcornReplacement.msgPump.hasOwnProperty(msg))
-    IriSP.PopcornReplacement.msgPump[msg] = [];
-
-  IriSP.PopcornReplacement.msgPump[msg].push(callback);
+/** base class for our popcorn-compatible players.
+ */
+IriSP.PopcornReplacement.player = function(container, options) {
+  /* the jwplayer calls the callbacks in the global space so we need to 
+     preserve them using IriSP.wrap */
+  this.callbacks = {
+      onReady:  IriSP.wrap(this, this.__initApi),
+      onTime:   IriSP.wrap(this, this.__timeHandler),
+      onPlay:   IriSP.wrap(this, this.__playHandler),
+      onPause:  IriSP.wrap(this, this.__pauseHandler),
+      onSeek:   IriSP.wrap(this, this.__seekHandler) 
+  };
+  
+  this.media = { 
+    "paused": true,
+    "muted": false
+  };
+    
+  this.container = container.slice(1); //eschew the '#'
+  
+  this.msgPump = {}; /* dictionnary used to receive and send messages */
+  this.__codes = []; /* used to schedule the execution of a piece of code in 
+                        a segment (similar to the popcorn.code plugin). */
+                          
 };
 
-IriSP.PopcornReplacement.trigger = function(msg, params) {
-//  IriSP.jQuery(IriSP.PopcornReplacement.msgPump).trigger(msg, params);
-  
-  if (!IriSP.PopcornReplacement.msgPump.hasOwnProperty(msg))
+IriSP.PopcornReplacement.player.prototype.listen = function(msg, callback) {
+  if (!this.msgPump.hasOwnProperty(msg))
+    this.msgPump[msg] = [];
+
+  this.msgPump[msg].push(callback);
+};
+
+IriSP.PopcornReplacement.player.prototype.trigger = function(msg, params) {
+  if (!this.msgPump.hasOwnProperty(msg))
     return;
 
-  var d = IriSP.PopcornReplacement.msgPump[msg];
+  var d = this.msgPump[msg];
 
   for(var i = 0; i < d.length; i++) {
     d[i].call(window, params);
@@ -33,7 +49,7 @@
 
 };
 
-IriSP.PopcornReplacement.guid = function(prefix) {
+IriSP.PopcornReplacement.player.prototype.guid = function(prefix) {
   var str = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
       var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
       return v.toString(16);
@@ -42,15 +58,17 @@
   return prefix + str;
 };
 
-IriSP.PopcornReplacement.__initApi = function() {
-  IriSP.PopcornReplacement.trigger("loadedmetadata"); // we've done more than loading metadata of course,
+/** init the api after that flash player has been setup - called by the callback
+    defined by the embedded flash player 
+*/
+IriSP.PopcornReplacement.player.prototype.__initApi = function() {
+  this.trigger("loadedmetadata"); // we've done more than loading metadata of course,
                                                       // but popcorn doesn't need to know more.
-  IriSP.PopcornReplacement.media.muted = jwplayer(IriSP.PopcornReplacement._container).getMute();
-  
+  this.media.muted = this.playerFns.getMute();
   /* some programmed segments are supposed to be run at the beginning */
   var i = 0;
-  for(i = 0; i < IriSP.PopcornReplacement.__codes.length; i++) {
-    var c = IriSP.PopcornReplacement.__codes[i];
+  for(i = 0; i < this.__codes.length; i++) {
+    var c = this.__codes[i];
     if (0 == c.start) {
       c.onStart();
     }
@@ -61,6 +79,7 @@
   }
 };
 
+/*
 IriSP.PopcornReplacement.jwplayer = function(container, options) {
   IriSP.PopcornReplacement._container = container.slice(1); //eschew the '#'
   options.events = {
@@ -75,73 +94,73 @@
   IriSP.PopcornReplacement.media.duration = options.duration;
   return IriSP.PopcornReplacement;
 };
+*/
 
-IriSP.PopcornReplacement.currentTime = function(time) {
+IriSP.PopcornReplacement.player.prototype.currentTime = function(time) {
   if (typeof(time) === "undefined") {        
-      return jwplayer(IriSP.PopcornReplacement._container).getPosition();            
+      return this.playerFns.getPosition();            
   } else {
      var currentTime = +time;
-     jwplayer( IriSP.PopcornReplacement._container ).seek( currentTime );
-     IriSP.PopcornReplacement.__delay_seek_signal = true;     
-     IriSP.PopcornReplacement.trigger("seeked");           
+     this.playerFns.seek( currentTime );
+     this.__delay_seek_signal = true;    /* FIXME : useless ? */
+     this.trigger("seeked");           
      return currentTime;
   }
 };
 
-IriSP.PopcornReplacement.play = function() {
-      IriSP.PopcornReplacement.media.paused = false;
-      IriSP.PopcornReplacement.trigger("play");
-//      IriSP.PopcornReplacement.trigger("playing");
-      jwplayer( IriSP.PopcornReplacement._container ).play();
+IriSP.PopcornReplacement.player.prototype.play = function() {
+  this.media.paused = false;
+  this.trigger("play");
+  //IriSP.PopcornReplacement.trigger("playing");
+  this.playerFns.play();
 };
     
-IriSP.PopcornReplacement.pause = function() {
-      if ( !IriSP.PopcornReplacement.media.paused ) {
-        IriSP.PopcornReplacement.media.paused = true;
-        IriSP.PopcornReplacement.trigger( "pause" );
-        jwplayer( IriSP.PopcornReplacement._container ).pause();
-      }
-};
-
-IriSP.PopcornReplacement.muted = function(val) {
-  if (typeof(val) !== "undefined") {
-
-    if (jwplayer(IriSP.PopcornReplacement._container).getMute() !== val) {
-      if (val) {
-        jwplayer(IriSP.PopcornReplacement._container).setMute(true);
-        IriSP.PopcornReplacement.media.muted = true;
-      } else {
-        jwplayer( IriSP.PopcornReplacement._container ).setMute(false);
-        IriSP.PopcornReplacement.media.muted = false;
-      }
-
-      IriSP.PopcornReplacement.trigger( "volumechange" );
-    }
-    
-    return jwplayer( IriSP.PopcornReplacement._container ).getMute();
-  } else {
-    return jwplayer( IriSP.PopcornReplacement._container ).getMute();
+IriSP.PopcornReplacement.player.prototype.pause = function() {
+  if ( !this.media.paused ) {
+    this.media.paused = true;
+    this.trigger( "pause" );
+    this.playerFns.pause();
   }
 };
 
-IriSP.PopcornReplacement.mute = IriSP.PopcornReplacement.muted;
+IriSP.PopcornReplacement.player.prototype.muted = function(val) {
+  if (typeof(val) !== "undefined") {
+
+    if (this.playerFns.getMute() !== val) {
+      if (val) {
+        this.playerFns.setMute(true);
+        this.media.muted = true;
+      } else {
+        this.playerFns.setMute(false);
+        this.media.muted = false;
+      }
 
-IriSP.PopcornReplacement.__codes = [];
-IriSP.PopcornReplacement.code = function(options) {
-  IriSP.PopcornReplacement.__codes.push(options);
-  return IriSP.PopcornReplacement;
+      this.trigger( "volumechange" );
+    }
+    
+    return this.playerFns.getMute();
+  } else {
+    return this.playerFns.getMute();
+  }
+};
+
+IriSP.PopcornReplacement.player.prototype.mute = IriSP.PopcornReplacement.player.prototype.muted;
+
+IriSP.PopcornReplacement.player.prototype.code = function(options) {
+  this.__codes.push(options);
+  return this;
 };
 
 /* called everytime the player updates itself 
    (onTime event)
  */
 
-IriSP.PopcornReplacement.__timeHandler = function(event) {
+IriSP.PopcornReplacement.player.prototype.__timeHandler = function(event) {
   var pos = event.position;
-  
+
   var i = 0;
-  for(i = 0; i < IriSP.PopcornReplacement.__codes.length; i++) {
-     var c = IriSP.PopcornReplacement.__codes[i];
+  for(i = 0; i < this.__codes.length; i++) {
+     var c = this.__codes[i];
 
      if (pos >= c.start && pos < c.end && 
          pos - 1 <= c.start) {       
@@ -155,22 +174,22 @@
    
   }
  
-  IriSP.PopcornReplacement.trigger("timeupdate");
+  this.trigger("timeupdate");
 };
 
-IriSP.PopcornReplacement.__seekHandler = function(event) {
+IriSP.PopcornReplacement.player.prototype.__seekHandler = function(event) {
   var i = 0;
-  
-  for(i = 0; i < IriSP.PopcornReplacement.__codes.length; i++) {
-     var c = IriSP.PopcornReplacement.__codes[i];
+
+  for(i = 0; i < this.__codes.length; i++) {
+     var c = this.__codes[i];
     
      if (event.position >= c.start && event.position < c.end) {        
         c.onEnd();
      }         
    }
   
-   for(i = 0; i < IriSP.PopcornReplacement.__codes.length; i++) {
-     var c = IriSP.PopcornReplacement.__codes[i];
+   for(i = 0; i < this.__codes.length; i++) {
+     var c = this.__codes[i];
 
      if (typeof(event.offset) === "undefined")
        event.offset = 0;
@@ -181,21 +200,48 @@
      
    }
 
-  IriSP.PopcornReplacement.trigger("timeupdate");
+  this.trigger("timeupdate");
+};
+
+IriSP.PopcornReplacement.player.prototype.__playHandler = function(event) {
+  this.media.paused = false;
+  this.trigger("play");
 };
 
+IriSP.PopcornReplacement.player.prototype.__pauseHandler = function(event) {
+  this.media.paused = true;
+  this.trigger("pause");
+};
 
-IriSP.PopcornReplacement.__playHandler = function(event) {
-  IriSP.PopcornReplacement.media.paused = false;
-  IriSP.PopcornReplacement.trigger("play");
+IriSP.PopcornReplacement.player.prototype.roundTime = function() {
+  var currentTime = this.currentTime();
+  return Math.round(currentTime);
 };
 
-IriSP.PopcornReplacement.__pauseHandler = function(event) {
-  IriSP.PopcornReplacement.media.paused = true;
-  IriSP.PopcornReplacement.trigger("pause");
+/* To wrap a player the develop should create a new class derived from 
+   the IriSP.PopcornReplacement.player and defining the correct functions */
+
+/* Exemple with jwplayer */
+IriSP.PopcornReplacement.jwplayer = function(container, options) {
+
+  /* appel du parent pour initialiser les structures communes à tous les players */
+  IriSP.PopcornReplacement.player.call(this, container, options);
+  
+  this.media.duration = options.duration; /* optional */
+  
+  /* Définition des fonctions de l'API -  */
+  this.playerFns = {
+    play: function() { return jwplayer(this.container).play(); },
+    pause: function() { return jwplayer(this.container).pause(); },
+    getPosition: function() { return jwplayer(this.container).getPosition(); },
+    seek: function(pos) { return jwplayer(this.container).seek(pos); },
+    getMute: function() { return jwplayer(this.container).getMute() },
+    setMute: function(p) { return jwplayer(this.container).setMute(p); }
+  }
+
+  options.events = this.callbacks;
+
+  jwplayer(this.container).setup(options);
 };
 
-IriSP.PopcornReplacement.roundTime = function() {
-  var currentTime = IriSP.PopcornReplacement.currentTime();
-  return Math.round(currentTime);
-};
+IriSP.PopcornReplacement.jwplayer.prototype = new IriSP.PopcornReplacement.player("", {});
--- a/src/js/widgets/annotationsListWidget.js	Mon Jan 23 17:27:37 2012 +0100
+++ b/src/js/widgets/annotationsListWidget.js	Wed Jan 25 15:38:46 2012 +0100
@@ -123,8 +123,7 @@
   
   for (i = 0; i < annotations.length; i++) {
       var annotation = annotations[i];
-      console.log(annotation);
-      console.log(view_types, annotation.meta["id-ref"]);
+
       /* filter the annotations whose type is not the one we want */
       /* We want _all_ the annotations.
       if (typeof(annotation.meta) !== "undefined" && typeof(annotation.meta["id-ref"]) !== "undefined"
@@ -143,7 +142,7 @@
       obj["url"] = document.location.href.split("#")[0] + "/" + annotation.meta["project"];
       l.push(obj);
   }
-  console.log(l);
+
   this.do_redraw(l);
 };
 IriSP.AnnotationsListWidget.prototype.draw = function() {
--- a/test/integration/polemic-platform.htm	Mon Jan 23 17:27:37 2012 +0100
+++ b/test/integration/polemic-platform.htm	Wed Jan 25 15:38:46 2012 +0100
@@ -22,10 +22,10 @@
   <div id="Sparkline"></div>
   <script  type="text/javascript">
     var platf_url = "http://localhost/pf/ldtplatform/ldt/";
-    var project_id = "47e3eef0-3ab4-11e1-9423-001d7d7c6d1d";
+    //var project_id = "47e3eef0-3ab4-11e1-9423-001d7d7c6d1d";
     //http://localhost/pf/ldtplatform/ldt/cljson/id/
     //var project_id = "1771a6cf-3dfd-11e1-a3d8-001d7d7c6d1d";
-    //var project_id = "1771a6cf-3dfd-11e1-a3d8-001d7d7c6d1d";
+    var project_id = "1771a6cf-3dfd-11e1-a3d8-001d7d7c6d1d";
     var json_src = platf_url + "cljson/id/" + project_id;
     
     IriSP.widgetsDefaults["createAnnotationWidget"].cinecast_version = false;
--- a/test/integration/polemic.htm	Mon Jan 23 17:27:37 2012 +0100
+++ b/test/integration/polemic.htm	Wed Jan 25 15:38:46 2012 +0100
@@ -140,11 +140,11 @@
             ]
         },
       player:{
-      type:'jwplayer', // player type
-              live: true, 
-              height: 300, 
-              width: 640, 
-              provider: "rtmp" 
+          type:'jwplayer', // player type - 
+          live: true, 
+          height: 300, 
+          width: 640, 
+          provider: "rtmp" 
       },
       modules: [
                { type: "MediaFragment",