added autoconfiguration of the media source for rtmp streams. popcorn-port
authorhamidouk
Tue, 13 Dec 2011 17:31:39 +0100
branchpopcorn-port
changeset 453 8568e47379a2
parent 452 35495f156c41
child 454 f921c98a180b
added autoconfiguration of the media source for rtmp streams.
src/js/data.js
src/js/init.js
src/js/main.js
test/integration/polemic.htm
--- a/src/js/data.js	Tue Dec 13 15:14:15 2011 +0100
+++ b/src/js/data.js	Tue Dec 13 17:31:39 2011 +0100
@@ -37,7 +37,7 @@
       
       /* automagically choose between json and jsonp */
       if (url.indexOf(document.location.hostname) === -1 &&
-          url[0] !== '/' /* not a relative url */ ) {
+          url.indexOf("http://") !== -1 /* not a relative url */ ) {
         // we contacting a foreign domain, use JSONP
 
         IriSP.jQuery.get(url, {}, IriSP.wrap(this, func), "jsonp");
--- a/src/js/init.js	Tue Dec 13 15:14:15 2011 +0100
+++ b/src/js/init.js	Tue Dec 13 17:31:39 2011 +0100
@@ -3,6 +3,13 @@
  
  */
 
+IriSP.setupDataLoader = function() {
+  /* we set it up separately because we need to
+     get data at the very beginning, for instance when
+     setting up the video */
+  IriSP.__dataloader = new IriSP.DataLoader();
+};
+
 IriSP.configurePopcorn = function (layoutManager, options) {
     var pop;
     var ret = layoutManager.createDiv(); 
@@ -29,6 +36,20 @@
       case "jwplayer":
           var opts = IriSP.jQuery.extend({}, options);
           delete opts.container;
+
+          /* 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"];
+
+          // the source if a full url but jwplayer wants an url relative to the
+          // streamer url, so we've got to remove the common part.
+          opts.file = source.slice(opts.streamer.length);
           pop = IriSP.PopcornReplacement.jwplayer("#" + containerDiv, opts);
         break;
       
@@ -53,10 +74,8 @@
 };
 
 IriSP.configureWidgets = function (popcornInstance, layoutManager, guiOptions) {
-
-  var dt = new IriSP.DataLoader();
-  var serialFactory = new IriSP.SerializerFactory(dt);
-  
+ 
+  var serialFactory = new IriSP.SerializerFactory(IriSP.__dataloader);
   var params = {width: guiOptions.width, height: guiOptions.height};
 
   var ret_widgets = [];
--- a/src/js/main.js	Tue Dec 13 15:14:15 2011 +0100
+++ b/src/js/main.js	Tue Dec 13 17:31:39 2011 +0100
@@ -7,7 +7,7 @@
 
 /* crap code will be the first against the wall when the
    revolution comes */
-IriSP.loadLibs = function( libs, customCssPath, callback ) {
+IriSP.loadLibs = function( libs, customCssPath, metadata_url, callback ) {
 		// Localize jQuery variable
 		IriSP.jQuery = null;
 
@@ -117,7 +117,14 @@
 					$( '.dynamic_css' ).clone().appendTo( 'head' );
 				}
         
-        callback();
+        IriSP.setupDataLoader();
+        IriSP.__dataloader.get(metadata_url, 
+            function(data) {
+              /* save the data so that we could re-use it to
+                 configure the video
+              */
+              IriSP.__jsonMetadata = data;
+              callback.call(window) });
       });
     }
 };
--- a/test/integration/polemic.htm	Tue Dec 13 15:14:15 2011 +0100
+++ b/test/integration/polemic.htm	Tue Dec 13 17:31:39 2011 +0100
@@ -103,10 +103,6 @@
         },
       player:{
       type:'jwplayer', // player type
-              container: 'PopcornContainer',
-              // the rest is player-dependent configuration options.
-              file : "video/ldtplatform/museologie_inaugurale_20111018_flat.f4v", 
-              streamer: "rtmp://media.iri.centrepompidou.fr/ddc_player/", 
               flashplayer : '../libs/player.swf',
               live: true, 
               "controlbar.position" : "none", 
@@ -116,7 +112,7 @@
             }
     };
     
-    IriSP.loadLibs(IriSP.lib, config.gui.css, 
+    IriSP.loadLibs(IriSP.lib, config.gui.css, "polemic_fr.json",
       function() {   
               var layoutManager = new IriSP.LayoutManager(config.gui.container);
               var pop = IriSP.configurePopcorn(layoutManager, config.player);