diff -r ed19b689de87 -r 3cc57cb48aea metadataplayer edwin/metadataplayer/LdtPlayer-core.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/metadataplayer edwin/metadataplayer/LdtPlayer-core.js Fri Jun 15 13:04:55 2012 +0200 @@ -0,0 +1,2354 @@ +/* + * + * Copyright 2010-2012 Institut de recherche et d'innovation + * contributor(s) : Karim Hamidou, Samuel Huron, Raphael Velt, Thibaut Cavalie + * + * contact@iri.centrepompidou.fr + * http://www.iri.centrepompidou.fr + * + * This software is a computer program whose purpose is to show and add annotations on a video . + * This software is governed by the CeCILL-C license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL-C + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL-C license and that you accept its terms. +*/ +/*! LAB.js (LABjs :: Loading And Blocking JavaScript) + v2.0.3 (c) Kyle Simpson + MIT License +*/ +(function(o){var K=o.$LAB,y="UseLocalXHR",z="AlwaysPreserveOrder",u="AllowDuplicates",A="CacheBust",B="BasePath",C=/^[^?#]*\//.exec(location.href)[0],D=/^\w+\:\/\/\/?[^\/]+/.exec(C)[0],i=document.head||document.getElementsByTagName("head"),L=(o.opera&&Object.prototype.toString.call(o.opera)=="[object Opera]")||("MozAppearance"in document.documentElement.style),q=document.createElement("script"),E=typeof q.preload=="boolean",r=E||(q.readyState&&q.readyState=="uninitialized"),F=!r&&q.async===true,M=!r&&!F&&!L;function G(a){return Object.prototype.toString.call(a)=="[object Function]"}function H(a){return Object.prototype.toString.call(a)=="[object Array]"}function N(a,c){var b=/^\w+\:\/\//;if(/^\/\/\/?/.test(a)){a=location.protocol+a}else if(!b.test(a)&&a.charAt(0)!="/"){a=(c||"")+a}return b.test(a)?a:((a.charAt(0)=="/"?D:C)+a)}function s(a,c){for(var b in a){if(a.hasOwnProperty(b)){c[b]=a[b]}}return c}function O(a){var c=false;for(var b=0;b0){for(var a=0;a=0;){d=n.shift();a=a[d.type].apply(null,d.args)}return a},noConflict:function(){o.$LAB=K;return m},sandbox:function(){return J()}};return m}o.$LAB=J();(function(a,c,b){if(document.readyState==null&&document[a]){document.readyState="loading";document[a](c,b=function(){document.removeEventListener(c,b,false);document.readyState="complete"},false)}})("addEventListener","DOMContentLoaded")})(this);/* init.js - initialization and configuration of Popcorn and the widgets +*/ + +if (typeof window.IriSP === "undefined") { + IriSP = {}; +} + +/* The Metadataplayer Object, single point of entry, replaces IriSP.init_player */ + +IriSP.Metadataplayer = function(config) { + IriSP.log("IriSP.Metadataplayer constructor"); + for (var key in IriSP.guiDefaults) { + if (IriSP.guiDefaults.hasOwnProperty(key) && !config.gui.hasOwnProperty(key)) { + config.gui[key] = IriSP.guiDefaults[key] + } + } + var _container = document.getElementById(config.gui.container); + _container.innerHTML = '

Loading... Chargement...

'; + this.sourceManager = new IriSP.Model.Directory(); + this.config = config; + this.callbackQueue = []; + this.isLoaded = false; + this.loadLibs(); +} + +IriSP.Metadataplayer.prototype.toString = function() { + return 'Metadataplayer in #' + this.config.gui.container; +} + +IriSP.Metadataplayer.prototype.deferCallback = function(_callback) { + var _this = this; + IriSP._.defer(function() { + _callback.call(_this); + }); +} + +IriSP.Metadataplayer.prototype.handleCallbacks = function() { + this.isLoaded = true; + while (this.callbackQueue.length) { + this.deferCallback(this.callbackQueue.splice(0,1)[0]); + } +} + +IriSP.Metadataplayer.prototype.onLoad = function(_callback) { + if (this.isLoaded) { + this.deferCallback(_callback); + } else { + this.callbackQueue.push(_callback); + } +} + +IriSP.Metadataplayer.prototype.loadLibs = function() { + IriSP.log("IriSP.Metadataplayer.prototype.loadLibs"); + var $L = $LAB + .script(IriSP.getLib("underscore")) + .script(IriSP.getLib("Mustache")) + .script(IriSP.getLib("jQuery")) + .script(IriSP.getLib("swfObject")) + .wait() + .script(IriSP.getLib("jQueryUI")); + + if (this.config.player.type === "jwplayer" || this.config.player.type === "auto") { + $L.script(IriSP.getLib("jwplayer")); + } + + if (this.config.player.type !== "jwplayer" && this.config.player.type !== "allocine" && this.config.player.type !== "dailymotion") { + $L.script(IriSP.getLib("popcorn")); + } + + /* widget specific requirements */ + for(var _i = 0; _i < this.config.gui.widgets.length; _i++) { + var _t = this.config.gui.widgets[_i].type; + if (typeof IriSP.widgetsRequirements[_t] !== "undefined" && typeof IriSP.widgetsRequirements[_t].requires !== "undefined") { + $L.script(IriSP.getLib(IriSP.widgetsRequirements[_t].requires)); + } + } + + var _this = this; + IriSP.log($L); + $L.wait(function() { + _this.onLibsLoaded(); + }); +} + +IriSP.Metadataplayer.prototype.onLibsLoaded = function() { + IriSP.log("IriSP.Metadataplayer.prototype.onLibsLoaded"); + if (typeof IriSP.jQuery === "undefined" && typeof window.jQuery !== "undefined") { + IriSP.jQuery = window.jQuery.noConflict(); + } + if (typeof IriSP._ === "undefined" && typeof window._ !== "undefined") { + IriSP._ = window._.noConflict(); + } + IriSP.loadCss(IriSP.getLib("cssjQueryUI")); + IriSP.loadCss(this.config.gui.css); + + this.videoData = this.loadMetadata(this.config.player.metadata); + this.$ = IriSP.jQuery('#' + this.config.gui.container); + this.$.css({ + "width": this.config.gui.width, + "clear": "both" + }); + if (typeof this.config.gui.height !== "undefined") { + this.$.css("height", this.config.gui.height); + } + + var _this = this; + this.videoData.onLoad(function() { + _this.onVideoDataLoaded(); + }); +} + +IriSP.Metadataplayer.prototype.loadMetadata = function(_metadataInfo) { + if (typeof _metadataInfo.serializer === "undefined" && typeof _metadataInfo.format !== "undefined") { + _metadataInfo.serializer = IriSP.serializers[_metadataInfo.format]; + } + if (typeof _metadataInfo.url === "undefined" && typeof _metadataInfo.src !== "undefined") { + _metadataInfo.url = _metadataInfo.src; + } + if (typeof _metadataInfo.url !== "undefined" && typeof _metadataInfo.serializer !== "undefined") { + return this.sourceManager.remoteSource(_metadataInfo); + } else { + return this.sourceManager.newLocalSource(_metadataInfo); + } +} + +IriSP.Metadataplayer.prototype.onVideoDataLoaded = function() { + if (typeof this.videoData !== "undefined" && typeof this.config.player.video === "undefined") { + var _media = this.videoData.currentMedia; + if (typeof _media !== "undefined") { + this.config.player.video = _media.video; + if (typeof _media.streamer !== "undefined") { + this.config.player.streamer = _media.streamer; + this.config.player.video = _media.video.replace(_media.streamer,''); + } + } + + } + this.configurePopcorn(); + this.widgets = []; + var _this = this; + for(var i = 0; i < this.config.gui.widgets.length; i++) { + this.loadWidget(this.config.gui.widgets[i], function(_widget) { + _this.widgets.push(_widget) + }); + }; + this.$.find('.Ldt-Loader').detach(); + this.handleCallbacks(); +} + +IriSP.Metadataplayer.prototype.loadWidget = function(_widgetConfig, _callback) { + /* Creating containers if needed */ + if (typeof _widgetConfig.container === "undefined") { + var _divs = this.layoutDivs(_widgetConfig.type); + _widgetConfig.container = _divs[0]; + } + + var _this = this; + + if (typeof IriSP.Widgets[_widgetConfig.type] !== "undefined") { + IriSP._.defer(function() { + _callback(new IriSP.Widgets[_widgetConfig.type](_this, _widgetConfig)); + }); + } else { + /* Loading Widget CSS */ + if (typeof IriSP.widgetsRequirements[_widgetConfig.type] === "undefined" || typeof IriSP.widgetsRequirements[_widgetConfig.type].noCss === "undefined" || !IriSP.widgetsRequirements[_widgetConfig.type].noCss) { + IriSP.loadCss(IriSP.widgetsDir + '/' + _widgetConfig.type + '.css'); + } + /* Loading Widget JS */ + $LAB.script(IriSP.widgetsDir + '/' + _widgetConfig.type + '.js').wait(function() { + _callback(new IriSP.Widgets[_widgetConfig.type](_this, _widgetConfig)); + }); + } +} + +IriSP.Metadataplayer.prototype.configurePopcorn = function() { + IriSP.log("IriSP.Metadataplayer.prototype.configurePopcorn"); + var pop, + ret = this.layoutDivs("video"), + containerDiv = ret[0], + spacerDiv = ret[1], + _this = this, + _types = { + "html5" : /\.(ogg|ogv|webm)$/, + "youtube" : /^(https?:\/\/)?(www\.)?youtube\.com/, + "dailymotion" : /^(https?:\/\/)?(www\.)?dailymotion\.com/ + }; + + if (this.config.player.type === "auto") { + this.config.player.type = "jwplayer"; + IriSP._(_types).each(function(_v, _k) { + if (_v.test(_this.config.player.video)) { + _this.config.player.type = _k + } + }); + } + + switch(this.config.player.type) { + /* + todo : dynamically create the div/video tag which + will contain the video. + */ + case "html5": + var _tmpId = Popcorn.guid("video"), + _videoEl = IriSP.jQuery('