src/js/init.js
branchnew-model
changeset 922 096c06aea8b5
parent 919 972099304059
child 924 64c2eaafe5e2
equal deleted inserted replaced
921:d4dc652bf050 922:096c06aea8b5
   127         return this.sourceManager.newLocalSource(_metadataInfo);
   127         return this.sourceManager.newLocalSource(_metadataInfo);
   128     }
   128     }
   129 }
   129 }
   130 
   130 
   131 IriSP.Metadataplayer.prototype.onVideoDataLoaded = function() {
   131 IriSP.Metadataplayer.prototype.onVideoDataLoaded = function() {
       
   132     
       
   133     /* Getting video URL from metadata if it's not in the player config options */
       
   134    
   132     if (typeof this.videoData !== "undefined" && typeof this.config.player.video === "undefined") {
   135     if (typeof this.videoData !== "undefined" && typeof this.config.player.video === "undefined") {
   133         
   136         
   134         var _media;
   137         var _media;
   135         
   138         
   136         if (typeof this.videoData.mainMedia !== "undefined") {
   139         if (typeof this.videoData.mainMedia !== "undefined") {
   162                 this.config.player.video = _media.video.replace(_media.streamer,'');
   165                 this.config.player.video = _media.video.replace(_media.streamer,'');
   163             }
   166             }
   164         }
   167         }
   165         
   168         
   166     }
   169     }
   167     this.configurePopcorn();
   170     
   168     this.widgets = [];
   171     if (typeof this.config.player.video === "string" && this.config.player.url_transform === "function") {
   169     var _this = this;
   172         this.config.player.video = this.config.player.url_transform(this.config.player.video);
   170     for(var i = 0; i < this.config.gui.widgets.length; i++) {
   173     }
   171         this.loadWidget(this.config.gui.widgets[i], function(_widget) {
   174     
   172             _this.widgets.push(_widget)
   175     var _pop,
   173         });
   176         _divs = this.layoutDivs("video",this.config.player.height || undefined),
   174     };
   177         containerDiv = _divs[0],
   175     this.$.find('.Ldt-Loader').detach();
   178         spacerDiv = _divs[1],
   176     this.handleCallbacks();
       
   177 }
       
   178 
       
   179 IriSP.Metadataplayer.prototype.loadWidget = function(_widgetConfig, _callback) {
       
   180     /* Creating containers if needed */
       
   181     if (typeof _widgetConfig.container === "undefined") {
       
   182         var _divs = this.layoutDivs(_widgetConfig.type);
       
   183         _widgetConfig.container = _divs[0];
       
   184     }
       
   185     
       
   186     var _this = this;
       
   187     
       
   188     if (typeof IriSP.Widgets[_widgetConfig.type] !== "undefined") {
       
   189         IriSP._.defer(function() {
       
   190             _callback(new IriSP.Widgets[_widgetConfig.type](_this, _widgetConfig));
       
   191         });
       
   192     } else {
       
   193         /* Loading Widget CSS */
       
   194         if (typeof IriSP.widgetsRequirements[_widgetConfig.type] === "undefined" || typeof IriSP.widgetsRequirements[_widgetConfig.type].noCss === "undefined" || !IriSP.widgetsRequirements[_widgetConfig.type].noCss) {
       
   195             IriSP.loadCss(IriSP.widgetsDir + '/' + _widgetConfig.type + '.css');
       
   196         }
       
   197         /* Loading Widget JS    */
       
   198         $LAB.script(IriSP.widgetsDir + '/' + _widgetConfig.type + '.js').wait(function() {
       
   199             _callback(new IriSP.Widgets[_widgetConfig.type](_this, _widgetConfig));
       
   200         });
       
   201     }
       
   202 }
       
   203 
       
   204 IriSP.Metadataplayer.prototype.configurePopcorn = function() {
       
   205     IriSP.log("IriSP.Metadataplayer.prototype.configurePopcorn");
       
   206     var pop,
       
   207         ret = this.layoutDivs("video",this.config.player.height || undefined),
       
   208         containerDiv = ret[0],
       
   209         spacerDiv = ret[1],
       
   210         _this = this,
   179         _this = this,
   211         _types = {
   180         _types = {
   212             "html5" : /\.(ogg|ogv|webm)$/,
   181             "html5" : /\.(ogg|ogv|webm)$/,
   213             "youtube" : /^(https?:\/\/)?(www\.)?youtube\.com/,
   182             "youtube" : /^(https?:\/\/)?(www\.)?youtube\.com/,
   214             "dailymotion" : /^(https?:\/\/)?(www\.)?dailymotion\.com/
   183             "dailymotion" : /^(https?:\/\/)?(www\.)?dailymotion\.com/
   222             }
   191             }
   223         });
   192         });
   224     }
   193     }
   225 
   194 
   226     switch(this.config.player.type) {
   195     switch(this.config.player.type) {
   227         /*
       
   228          todo : dynamically create the div/video tag which
       
   229          will contain the video.
       
   230          */
       
   231         case "html5":
   196         case "html5":
   232             var _tmpId = Popcorn.guid("video"),
   197             var _tmpId = Popcorn.guid("video"),
   233                 _videoEl = IriSP.jQuery('<video>');
   198                 _videoEl = IriSP.jQuery('<video>');
   234             
   199             
   235             _videoEl.attr({
   200             _videoEl.attr({
   242             }
   207             }
   243             if(this.config.player.hasOwnProperty("height")) {
   208             if(this.config.player.hasOwnProperty("height")) {
   244                 _videoEl.attr("height", this.config.player.height);
   209                 _videoEl.attr("height", this.config.player.height);
   245             }
   210             }
   246             IriSP.jQuery("#" + containerDiv).append(_videoEl);
   211             IriSP.jQuery("#" + containerDiv).append(_videoEl);
   247             pop = Popcorn("#" + _tmpId);
   212             _pop = Popcorn("#" + _tmpId);
   248             break;
   213             break;
   249 
   214 
   250         case "html5-audio":
   215         case "html5-audio":
   251             var _tmpId = Popcorn.guid("audio"),
   216             var _tmpId = Popcorn.guid("audio"),
   252                 _videoEl = IriSP.jQuery('<audio>');
   217                 _videoEl = IriSP.jQuery('<audio>');
   261             }
   226             }
   262             if(this.config.player.hasOwnProperty("height")) {
   227             if(this.config.player.hasOwnProperty("height")) {
   263                 _videoEl.attr("height", this.config.player.height);
   228                 _videoEl.attr("height", this.config.player.height);
   264             }
   229             }
   265             IriSP.jQuery("#" + containerDiv).append(_videoEl);
   230             IriSP.jQuery("#" + containerDiv).append(_videoEl);
   266             pop = Popcorn("#" + _tmpId);
   231             _pop = Popcorn("#" + _tmpId);
   267             break;
   232             break;
   268 
   233 
   269         case "jwplayer":
   234         case "jwplayer":
   270             var opts = IriSP.jQuery.extend({}, this.config.player);
   235             var opts = IriSP.jQuery.extend({}, this.config.player);
   271             delete opts.container;
   236             delete opts.container;
   278             }
   243             }
   279 
   244 
   280             if(!opts.hasOwnProperty("controlbar.position")) {
   245             if(!opts.hasOwnProperty("controlbar.position")) {
   281                 opts["controlbar.position"] = "none";
   246                 opts["controlbar.position"] = "none";
   282             }
   247             }
   283             pop = new IriSP.PopcornReplacement.jwplayer("#" + containerDiv, opts);
   248             _pop = new IriSP.PopcornReplacement.jwplayer("#" + containerDiv, opts);
   284             break;
   249             break;
   285 
   250 
   286         case "youtube":
   251         case "youtube":
   287             // Popcorn.youtube wants us to specify the size of the player in the style attribute of its container div.
   252             // Popcorn.youtube wants us to specify the size of the player in the style attribute of its container div.
   288             IriSP.jQuery("#" + containerDiv).css({
   253             IriSP.jQuery("#" + containerDiv).css({
   296                 _params[_ppart[0]] = decodeURIComponent(_ppart[1]);
   261                 _params[_ppart[0]] = decodeURIComponent(_ppart[1]);
   297             }
   262             }
   298             _params.controls = 0;
   263             _params.controls = 0;
   299             _params.modestbranding = 1;
   264             _params.modestbranding = 1;
   300             _url = _urlparts[0] + '?' + IriSP.jQuery.param(_params);
   265             _url = _urlparts[0] + '?' + IriSP.jQuery.param(_params);
   301             pop = Popcorn.youtube("#" + containerDiv, _url);
   266             _pop = Popcorn.youtube("#" + containerDiv, _url);
   302             break;
   267             break;
   303 
   268 
   304         case "dailymotion":
   269         case "dailymotion":
   305             pop = new IriSP.PopcornReplacement.dailymotion("#" + containerDiv, this.config.player);
   270             _pop = new IriSP.PopcornReplacement.dailymotion("#" + containerDiv, this.config.player);
   306             break;
   271             break;
   307 
   272 
   308         case "mashup":
   273         case "mashup":
   309             pop = new IriSP.PopcornReplacement.mashup("#" + containerDiv, this.config.player);
   274             _pop = new IriSP.PopcornReplacement.mashup("#" + containerDiv, this.config.player);
   310             break;
   275             break;
   311             
   276             
   312         case "allocine":
   277         case "allocine":
   313             /* pass the options as-is to the allocine player and let it handle everything */
   278             _pop = new IriSP.PopcornReplacement.allocine("#" + containerDiv, this.config.player);
   314             pop = new IriSP.PopcornReplacement.allocine("#" + containerDiv, this.config.player);
       
   315             break;
   279             break;
   316         
   280         
   317         case "mashup-html":
   281         case "mashup-html":
   318             pop = new IriSP.PopcornReplacement.htmlMashup("#" + containerDiv, this.config.player, this.videoData);
   282             _pop = new IriSP.PopcornReplacement.htmlMashup("#" + containerDiv, this.config.player, this.videoData);
   319             break;
   283             break;
   320         
   284         
   321         default:
   285         default:
   322             pop = undefined;
   286             _pop = undefined;
   323     };
   287     };
   324 
   288 
   325     this.popcorn = pop;
   289     this.popcorn = _pop;
       
   290     
       
   291     /* Now Loading Widgets */
       
   292     
       
   293     this.widgets = [];
       
   294     var _this = this;
       
   295     for(var i = 0; i < this.config.gui.widgets.length; i++) {
       
   296         this.loadWidget(this.config.gui.widgets[i], function(_widget) {
       
   297             _this.widgets.push(_widget)
       
   298         });
       
   299     };
       
   300     this.$.find('.Ldt-Loader').detach();
       
   301     this.handleCallbacks();
       
   302 }
       
   303 
       
   304 IriSP.Metadataplayer.prototype.loadWidget = function(_widgetConfig, _callback) {
       
   305     /* Creating containers if needed */
       
   306     if (typeof _widgetConfig.container === "undefined") {
       
   307         var _divs = this.layoutDivs(_widgetConfig.type);
       
   308         _widgetConfig.container = _divs[0];
       
   309     }
       
   310     
       
   311     var _this = this;
       
   312     
       
   313     if (typeof IriSP.Widgets[_widgetConfig.type] !== "undefined") {
       
   314         IriSP._.defer(function() {
       
   315             _callback(new IriSP.Widgets[_widgetConfig.type](_this, _widgetConfig));
       
   316         });
       
   317     } else {
       
   318         /* Loading Widget CSS */
       
   319         if (typeof IriSP.widgetsRequirements[_widgetConfig.type] === "undefined" || typeof IriSP.widgetsRequirements[_widgetConfig.type].noCss === "undefined" || !IriSP.widgetsRequirements[_widgetConfig.type].noCss) {
       
   320             IriSP.loadCss(IriSP.widgetsDir + '/' + _widgetConfig.type + '.css');
       
   321         }
       
   322         /* Loading Widget JS    */
       
   323         $LAB.script(IriSP.widgetsDir + '/' + _widgetConfig.type + '.js').wait(function() {
       
   324             _callback(new IriSP.Widgets[_widgetConfig.type](_this, _widgetConfig));
       
   325         });
       
   326     }
   326 }
   327 }
   327 
   328 
   328 /** create a subdiv with an unique id, and a spacer div as well.
   329 /** create a subdiv with an unique id, and a spacer div as well.
   329     @param widgetName the name of the widget.
   330     @param widgetName the name of the widget.
   330     @return an array of the form [createdivId, spacerdivId].
   331     @return an array of the form [createdivId, spacerdivId].