|
1 /* |
|
2 * |
|
3 * Copyright 2010-2012 Institut de recherche et d'innovation |
|
4 * contributor(s) : Karim Hamidou, Samuel Huron, Raphael Velt, Thibaut Cavalie |
|
5 * |
|
6 * contact@iri.centrepompidou.fr |
|
7 * http://www.iri.centrepompidou.fr |
|
8 * |
|
9 * This software is a computer program whose purpose is to show and add annotations on a video . |
|
10 * This software is governed by the CeCILL-C license under French law and |
|
11 * abiding by the rules of distribution of free software. You can use, |
|
12 * modify and/ or redistribute the software under the terms of the CeCILL-C |
|
13 * license as circulated by CEA, CNRS and INRIA at the following URL |
|
14 * "http://www.cecill.info". |
|
15 * |
|
16 * The fact that you are presently reading this means that you have had |
|
17 * knowledge of the CeCILL-C license and that you accept its terms. |
|
18 */ |
|
19 /*! LAB.js (LABjs :: Loading And Blocking JavaScript) |
|
20 v2.0.3 (c) Kyle Simpson |
|
21 MIT License |
|
22 */ |
|
23 (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;b<a.scripts.length;b++){if(a.scripts[b].ready&&a.scripts[b].exec_trigger){c=true;a.scripts[b].exec_trigger();a.scripts[b].exec_trigger=null}}return c}function t(a,c,b,d){a.onload=a.onreadystatechange=function(){if((a.readyState&&a.readyState!="complete"&&a.readyState!="loaded")||c[b])return;a.onload=a.onreadystatechange=null;d()}}function I(a){a.ready=a.finished=true;for(var c=0;c<a.finished_listeners.length;c++){a.finished_listeners[c]()}a.ready_listeners=[];a.finished_listeners=[]}function P(d,f,e,g,h){setTimeout(function(){var a,c=f.real_src,b;if("item"in i){if(!i[0]){setTimeout(arguments.callee,25);return}i=i[0]}a=document.createElement("script");if(f.type)a.type=f.type;if(f.charset)a.charset=f.charset;if(h){if(r){e.elem=a;if(E){a.preload=true;a.onpreload=g}else{a.onreadystatechange=function(){if(a.readyState=="loaded")g()}}a.src=c}else if(h&&c.indexOf(D)==0&&d[y]){b=new XMLHttpRequest();b.onreadystatechange=function(){if(b.readyState==4){b.onreadystatechange=function(){};e.text=b.responseText+"\n//@ sourceURL="+c;g()}};b.open("GET",c);b.send()}else{a.type="text/cache-script";t(a,e,"ready",function(){i.removeChild(a);g()});a.src=c;i.insertBefore(a,i.firstChild)}}else if(F){a.async=false;t(a,e,"finished",g);a.src=c;i.insertBefore(a,i.firstChild)}else{t(a,e,"finished",g);a.src=c;i.insertBefore(a,i.firstChild)}},0)}function J(){var l={},Q=r||M,n=[],p={},m;l[y]=true;l[z]=false;l[u]=false;l[A]=false;l[B]="";function R(a,c,b){var d;function f(){if(d!=null){d=null;I(b)}}if(p[c.src].finished)return;if(!a[u])p[c.src].finished=true;d=b.elem||document.createElement("script");if(c.type)d.type=c.type;if(c.charset)d.charset=c.charset;t(d,b,"finished",f);if(b.elem){b.elem=null}else if(b.text){d.onload=d.onreadystatechange=null;d.text=b.text}else{d.src=c.real_src}i.insertBefore(d,i.firstChild);if(b.text){f()}}function S(c,b,d,f){var e,g,h=function(){b.ready_cb(b,function(){R(c,b,e)})},j=function(){b.finished_cb(b,d)};b.src=N(b.src,c[B]);b.real_src=b.src+(c[A]?((/\?.*$/.test(b.src)?"&_":"?_")+~~(Math.random()*1E9)+"="):"");if(!p[b.src])p[b.src]={items:[],finished:false};g=p[b.src].items;if(c[u]||g.length==0){e=g[g.length]={ready:false,finished:false,ready_listeners:[h],finished_listeners:[j]};P(c,b,e,((f)?function(){e.ready=true;for(var a=0;a<e.ready_listeners.length;a++){e.ready_listeners[a]()}e.ready_listeners=[]}:function(){I(e)}),f)}else{e=g[0];if(e.finished){j()}else{e.finished_listeners.push(j)}}}function v(){var e,g=s(l,{}),h=[],j=0,w=false,k;function T(a,c){a.ready=true;a.exec_trigger=c;x()}function U(a,c){a.ready=a.finished=true;a.exec_trigger=null;for(var b=0;b<c.scripts.length;b++){if(!c.scripts[b].finished)return}c.finished=true;x()}function x(){while(j<h.length){if(G(h[j])){try{h[j++]()}catch(err){}continue}else if(!h[j].finished){if(O(h[j]))continue;break}j++}if(j==h.length){w=false;k=false}}function V(){if(!k||!k.scripts){h.push(k={scripts:[],finished:true})}}e={script:function(){for(var f=0;f<arguments.length;f++){(function(a,c){var b;if(!H(a)){c=[a]}for(var d=0;d<c.length;d++){V();a=c[d];if(G(a))a=a();if(!a)continue;if(H(a)){b=[].slice.call(a);b.unshift(d,1);[].splice.apply(c,b);d--;continue}if(typeof a=="string")a={src:a};a=s(a,{ready:false,ready_cb:T,finished:false,finished_cb:U});k.finished=false;k.scripts.push(a);S(g,a,k,(Q&&w));w=true;if(g[z])e.wait()}})(arguments[f],arguments[f])}return e},wait:function(){if(arguments.length>0){for(var a=0;a<arguments.length;a++){h.push(arguments[a])}k=h[h.length-1]}else k=false;x();return e}};return{script:e.script,wait:e.wait,setOptions:function(a){s(a,g);return e}}}m={setGlobalDefaults:function(a){s(a,l);return m},setOptions:function(){return v().setOptions.apply(null,arguments)},script:function(){return v().script.apply(null,arguments)},wait:function(){return v().wait.apply(null,arguments)},queueScript:function(){n[n.length]={type:"script",args:[].slice.call(arguments)};return m},queueWait:function(){n[n.length]={type:"wait",args:[].slice.call(arguments)};return m},runQueue:function(){var a=m,c=n.length,b=c,d;for(;--b>=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 |
|
24 */ |
|
25 |
|
26 if (typeof window.IriSP === "undefined") { |
|
27 IriSP = {}; |
|
28 } |
|
29 |
|
30 /* The Metadataplayer Object, single point of entry, replaces IriSP.init_player */ |
|
31 |
|
32 IriSP.Metadataplayer = function(config, video_metadata) { |
|
33 for (var key in IriSP.guiDefaults) { |
|
34 if (IriSP.guiDefaults.hasOwnProperty(key) && !config.gui.hasOwnProperty(key)) { |
|
35 config.gui[key] = IriSP.guiDefaults[key] |
|
36 } |
|
37 } |
|
38 var _container = document.getElementById(config.gui.container); |
|
39 _container.innerHTML = '<h3 class="Ldt-Loader">Loading... Chargement...</h3>'; |
|
40 this.video_metadata = video_metadata; |
|
41 this.sourceManager = new IriSP.Model.Directory(); |
|
42 this.config = config; |
|
43 this.loadLibs(); |
|
44 } |
|
45 |
|
46 IriSP.Metadataplayer.prototype.toString = function() { |
|
47 return 'A Metadataplayer in DIV #' + this.config.gui.container; |
|
48 } |
|
49 |
|
50 IriSP.Metadataplayer.prototype.loadLibs = function() { |
|
51 |
|
52 var $L = $LAB.script(IriSP.getLib("underscore")).script(IriSP.getLib("Mustache")).script(IriSP.getLib("jQuery")).script(IriSP.getLib("swfObject")).wait().script(IriSP.getLib("jQueryUI")); |
|
53 |
|
54 if(this.config.player.type === "jwplayer" || this.config.player.type === "allocine" || this.config.player.type === "dailymotion") { |
|
55 // load our popcorn.js lookalike |
|
56 $L.script(IriSP.getLib("jwplayer")); |
|
57 } else { |
|
58 // load the real popcorn |
|
59 $L.script(IriSP.getLib("popcorn")).script(IriSP.getLib("popcorn.code")); |
|
60 // load plugins if necessary |
|
61 if(this.config.player.type === "youtube") { |
|
62 $L.script(IriSP.getLib("popcorn.youtube")); |
|
63 } |
|
64 if(this.config.player.type === "vimeo"){ |
|
65 $L.script(IriSP.getLib("popcorn.vimeo")); |
|
66 } |
|
67 } |
|
68 |
|
69 /* widget specific requirements */ |
|
70 for(var _i = 0; _i < this.config.gui.widgets.length; _i++) { |
|
71 var _t = this.config.gui.widgets[_i].type; |
|
72 if (typeof IriSP.widgetsRequirements[_t] !== "undefined" && typeof IriSP.widgetsRequirements[_t].requires !== "undefined") { |
|
73 $L.script(IriSP.getLib(IriSP.widgetsRequirements[_t].requires)); |
|
74 } |
|
75 } |
|
76 |
|
77 var _this = this; |
|
78 |
|
79 $L.wait(function() { |
|
80 IriSP.jQuery = window.jQuery.noConflict(); |
|
81 IriSP._ = window._.noConflict(); |
|
82 |
|
83 IriSP.loadCss(IriSP.getLib("cssjQueryUI")) |
|
84 IriSP.loadCss(_this.config.gui.css); |
|
85 |
|
86 _this.onLibsLoaded(); |
|
87 |
|
88 }); |
|
89 } |
|
90 |
|
91 IriSP.Metadataplayer.prototype.onLibsLoaded = function() { |
|
92 this.videoData = this.loadMetadata(this.video_metadata); |
|
93 this.$ = IriSP.jQuery('#' + this.config.gui.container); |
|
94 this.$.css({ |
|
95 "width": this.config.gui.width, |
|
96 "clear": "both" |
|
97 }); |
|
98 if (typeof this.config.gui.height !== "undefined") { |
|
99 this.$.css("height", this.config.gui.height); |
|
100 } |
|
101 |
|
102 var _this = this; |
|
103 this.videoData.onLoad(function() { |
|
104 _this.onVideoDataLoaded(); |
|
105 }); |
|
106 } |
|
107 |
|
108 IriSP.Metadataplayer.prototype.loadMetadata = function(_metadataInfo) { |
|
109 if (typeof _metadataInfo.serializer === "undefined" && typeof _metadataInfo.format !== "undefined") { |
|
110 _metadataInfo.serializer = IriSP.serializers[_metadataInfo.format]; |
|
111 } |
|
112 if (typeof _metadataInfo.url === "undefined" && typeof _metadataInfo.src !== "undefined") { |
|
113 _metadataInfo.url = _metadataInfo.src; |
|
114 } |
|
115 if (typeof _metadataInfo.url !== "undefined" && typeof _metadataInfo.serializer !== "undefined") { |
|
116 return this.sourceManager.remoteSource(_metadataInfo); |
|
117 } else { |
|
118 return this.sourceManager.newLocalSource(_metadataInfo); |
|
119 } |
|
120 } |
|
121 |
|
122 IriSP.Metadataplayer.prototype.onVideoDataLoaded = function() { |
|
123 if (typeof this.videoData !== "undefined" && typeof this.config.player.video === "undefined") { |
|
124 var _media = this.videoData.currentMedia; |
|
125 if (typeof _media !== "undefined") { |
|
126 this.config.player.video = _media.video; |
|
127 if (typeof _media.streamer !== "undefined") { |
|
128 this.config.player.streamer = _media.streamer; |
|
129 this.config.player.video = _media.video.replace(_media.streamer,''); |
|
130 } |
|
131 } |
|
132 |
|
133 } |
|
134 this.configurePopcorn(); |
|
135 this.widgets = []; |
|
136 var _this = this; |
|
137 for(var i = 0; i < this.config.gui.widgets.length; i++) { |
|
138 this.loadWidget(this.config.gui.widgets[i], function(_widget) { |
|
139 _this.widgets.push(_widget) |
|
140 }); |
|
141 }; |
|
142 this.$.find('.Ldt-Loader').detach(); |
|
143 } |
|
144 |
|
145 IriSP.Metadataplayer.prototype.loadWidget = function(_widgetConfig, _callback) { |
|
146 /* Creating containers if needed */ |
|
147 if (typeof _widgetConfig.container === "undefined") { |
|
148 var _divs = this.layoutDivs(_widgetConfig.type); |
|
149 _widgetConfig.container = _divs[0]; |
|
150 } |
|
151 |
|
152 var _this = this; |
|
153 |
|
154 if (typeof IriSP.Widgets[_widgetConfig.type] !== "undefined") { |
|
155 IriSP._.defer(function() { |
|
156 _callback(new IriSP.Widgets[_widgetConfig.type](_this, _widgetConfig)); |
|
157 }); |
|
158 } else { |
|
159 /* Loading Widget CSS */ |
|
160 if (typeof IriSP.widgetsRequirements[_widgetConfig.type] === "undefined" || typeof IriSP.widgetsRequirements[_widgetConfig.type].noCss === "undefined" || !IriSP.widgetsRequirements[_widgetConfig.type].noCss) { |
|
161 IriSP.loadCss(IriSP.widgetsDir + '/' + _widgetConfig.type + '.css'); |
|
162 } |
|
163 /* Loading Widget JS */ |
|
164 $LAB.script(IriSP.widgetsDir + '/' + _widgetConfig.type + '.js').wait(function() { |
|
165 _callback(new IriSP.Widgets[_widgetConfig.type](_this, _widgetConfig)); |
|
166 }); |
|
167 } |
|
168 } |
|
169 |
|
170 IriSP.Metadataplayer.prototype.configurePopcorn = function() { |
|
171 var pop, |
|
172 ret = this.layoutDivs("video"), |
|
173 containerDiv = ret[0], |
|
174 spacerDiv = ret[1]; |
|
175 |
|
176 switch(this.config.player.type) { |
|
177 /* |
|
178 todo : dynamically create the div/video tag which |
|
179 will contain the video. |
|
180 */ |
|
181 case "html5": |
|
182 var tmpId = Popcorn.guid("video"); |
|
183 IriSP.jQuery("#" + containerDiv).append("<video src='" + this.config.player.video + "' id='" + tmpId + "'></video>"); |
|
184 |
|
185 if(options.hasOwnProperty("width")) |
|
186 IriSP.jQuery("#" + containerDiv).css("width", this.config.player.width); |
|
187 |
|
188 if(options.hasOwnProperty("height")) |
|
189 IriSP.jQuery("#" + containerDiv).css("height", this.config.player.height); |
|
190 pop = Popcorn("#" + tmpId); |
|
191 break; |
|
192 |
|
193 case "jwplayer": |
|
194 var opts = IriSP.jQuery.extend({}, this.config.player); |
|
195 delete opts.container; |
|
196 delete opts.type; |
|
197 opts.file = opts.video; |
|
198 delete opts.video; |
|
199 |
|
200 if(!opts.hasOwnProperty("flashplayer")) { |
|
201 opts.flashplayer = IriSP.jwplayer_swf_path; |
|
202 } |
|
203 |
|
204 if(!opts.hasOwnProperty("controlbar.position")) { |
|
205 opts["controlbar.position"] = "none"; |
|
206 } |
|
207 pop = new IriSP.PopcornReplacement.jwplayer("#" + containerDiv, opts); |
|
208 break; |
|
209 |
|
210 case "youtube": |
|
211 var opts = IriSP.jQuery.extend({}, this.config.player); |
|
212 delete opts.container; |
|
213 opts.controls = 0; |
|
214 opts.autostart = false; |
|
215 // Popcorn.youtube wants us to specify the size of the player in the style attribute of its container div. |
|
216 IriSP.jQuery("#" + containerDiv).css({ |
|
217 width : opts.width + "px", |
|
218 height : opts.height + "px" |
|
219 }) |
|
220 pop = Popcorn.youtube("#" + containerDiv, opts.video, opts); |
|
221 break; |
|
222 |
|
223 case "dailymotion": |
|
224 pop = new IriSP.PopcornReplacement.dailymotion("#" + containerDiv, this.config.player); |
|
225 break; |
|
226 |
|
227 case "allocine": |
|
228 /* pass the options as-is to the allocine player and let it handle everything */ |
|
229 pop = new IriSP.PopcornReplacement.allocine("#" + containerDiv, this.config.player); |
|
230 break; |
|
231 |
|
232 default: |
|
233 pop = undefined; |
|
234 }; |
|
235 |
|
236 this.popcorn = pop; |
|
237 } |
|
238 |
|
239 /** create a subdiv with an unique id, and a spacer div as well. |
|
240 @param widgetName the name of the widget. |
|
241 @return an array of the form [createdivId, spacerdivId]. |
|
242 */ |
|
243 IriSP.Metadataplayer.prototype.layoutDivs = function(_name) { |
|
244 if (typeof(_name) === "undefined") { |
|
245 _name = ""; |
|
246 } |
|
247 var newDiv = IriSP._.uniqueId(this.config.gui.container + "_widget_" + _name + "_"), |
|
248 spacerDiv = IriSP._.uniqueId("LdtPlayer_spacer_"), |
|
249 divHtml = IriSP.jQuery('<div>') |
|
250 .attr("id",newDiv) |
|
251 .css({ |
|
252 width: this.config.gui.width + "px", |
|
253 position: "relative", |
|
254 clear: "both" |
|
255 }), |
|
256 spacerHtml = IriSP.jQuery('<div>') |
|
257 .attr("id",spacerDiv) |
|
258 .css({ |
|
259 width: this.config.gui.width + "px", |
|
260 height: this.config.gui.spacer_div_height + "px", |
|
261 position: "relative", |
|
262 clear: "both" |
|
263 }); |
|
264 |
|
265 this.$.append(divHtml); |
|
266 this.$.append(spacerHtml); |
|
267 |
|
268 return [newDiv, spacerDiv]; |
|
269 }; |
|
270 /* utils.js - various utils that don't belong anywhere else */ |
|
271 |
|
272 IriSP.jqEscape = function(_text) { |
|
273 return text.replace(/(:|\.)/g,'\\$1'); |
|
274 } |
|
275 |
|
276 IriSP.getLib = function(lib) { |
|
277 if (IriSP.libFiles.useCdn && typeof IriSP.libFiles.cdn[lib] == "string") { |
|
278 return IriSP.libFiles.cdn[lib]; |
|
279 } |
|
280 if (typeof IriSP.libFiles.locations[lib] == "string") { |
|
281 return IriSP.libFiles.locations[lib]; |
|
282 } |
|
283 if (typeof IriSP.libFiles.inDefaultDir[lib] == "string") { |
|
284 return IriSP.libFiles.defaultDir + '/' + IriSP.libFiles.inDefaultDir[lib]; |
|
285 } |
|
286 } |
|
287 |
|
288 IriSP.loadCss = function(_cssFile) { |
|
289 IriSP.jQuery("<link>", { |
|
290 rel : "stylesheet", |
|
291 type : "text/css", |
|
292 href : _cssFile |
|
293 }).appendTo('head'); |
|
294 }/* wrapper that simulates popcorn.js because |
|
295 popcorn is a bit unstable at the time */ |
|
296 |
|
297 IriSP.PopcornReplacement = { |
|
298 }; |
|
299 |
|
300 /** base class for our popcorn-compatible players. |
|
301 */ |
|
302 IriSP.PopcornReplacement.player = function(container, options) { |
|
303 /* the jwplayer calls the callbacks in the global space so we need to |
|
304 preserve them this way */ |
|
305 if (typeof IriSP._ === "undefined") { |
|
306 return; |
|
307 } |
|
308 |
|
309 this.callbacks = { |
|
310 onReady: IriSP._.bind(this.__initApi, this), |
|
311 onTime: IriSP._.bind(this.__timeHandler, this), |
|
312 onPlay: IriSP._.bind(this.__playHandler, this), |
|
313 onPause: IriSP._.bind(this.__pauseHandler, this), |
|
314 onSeek: IriSP._.bind(this.__seekHandler, this) |
|
315 }; |
|
316 |
|
317 this.media = { |
|
318 "paused": true, |
|
319 "muted": false |
|
320 }; |
|
321 |
|
322 this.container = container.slice(1); //eschew the '#' |
|
323 |
|
324 this.msgPump = {}; /* dictionnary used to receive and send messages */ |
|
325 this.__codes = []; /* used to schedule the execution of a piece of code in |
|
326 a segment (similar to the popcorn.code plugin). */ |
|
327 |
|
328 this._options = options; |
|
329 |
|
330 }; |
|
331 |
|
332 IriSP.PopcornReplacement.player.prototype.listen = function(msg, callback) { |
|
333 if (!this.msgPump.hasOwnProperty(msg)) |
|
334 this.msgPump[msg] = []; |
|
335 |
|
336 this.msgPump[msg].push(callback); |
|
337 }; |
|
338 |
|
339 IriSP.PopcornReplacement.player.prototype.trigger = function(msg, params) { |
|
340 if (!this.msgPump.hasOwnProperty(msg)) |
|
341 return; |
|
342 |
|
343 var d = this.msgPump[msg]; |
|
344 |
|
345 for(var i = 0; i < d.length; i++) { |
|
346 d[i].call(window, params); |
|
347 } |
|
348 |
|
349 }; |
|
350 |
|
351 IriSP.PopcornReplacement.player.prototype.guid = function(prefix) { |
|
352 var str = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { |
|
353 var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8); |
|
354 return v.toString(16); |
|
355 }); |
|
356 |
|
357 return prefix + str; |
|
358 }; |
|
359 |
|
360 /** init the api after that flash player has been setup - called by the callback |
|
361 defined by the embedded flash player |
|
362 */ |
|
363 IriSP.PopcornReplacement.player.prototype.__initApi = function() { |
|
364 this.trigger("loadedmetadata"); // we've done more than loading metadata of course, |
|
365 // but popcorn doesn't need to know more. |
|
366 this.media.muted = this.playerFns.getMute(); |
|
367 /* some programmed segments are supposed to be run at the beginning */ |
|
368 var i = 0; |
|
369 for(i = 0; i < this.__codes.length; i++) { |
|
370 var c = this.__codes[i]; |
|
371 if (0 == c.start) { |
|
372 c.onStart(); |
|
373 } |
|
374 |
|
375 if (0 == c.end) { |
|
376 c.onEnd(); |
|
377 } |
|
378 } |
|
379 }; |
|
380 |
|
381 IriSP.PopcornReplacement.player.prototype.currentTime = function(time) { |
|
382 if (typeof(time) === "undefined") { |
|
383 return this.playerFns.getPosition(); |
|
384 } else { |
|
385 var currentTime = +time; |
|
386 this.playerFns.seek(currentTime); |
|
387 return currentTime; |
|
388 } |
|
389 }; |
|
390 |
|
391 IriSP.PopcornReplacement.player.prototype.play = function() { |
|
392 this.media.paused = false; |
|
393 this.trigger("play"); |
|
394 //IriSP.PopcornReplacement.trigger("playing"); |
|
395 this.playerFns.play(); |
|
396 }; |
|
397 |
|
398 IriSP.PopcornReplacement.player.prototype.pause = function() { |
|
399 // if ( !this.media.paused ) { |
|
400 this.media.paused = true; |
|
401 this.trigger( "pause" ); |
|
402 this.playerFns.pause(); |
|
403 // } |
|
404 }; |
|
405 |
|
406 IriSP.PopcornReplacement.player.prototype.muted = function(val) { |
|
407 if (typeof(val) !== "undefined") { |
|
408 |
|
409 if (this.playerFns.getMute() !== val) { |
|
410 if (val) { |
|
411 this.playerFns.setMute(true); |
|
412 this.media.muted = true; |
|
413 } else { |
|
414 this.playerFns.setMute(false); |
|
415 this.media.muted = false; |
|
416 } |
|
417 |
|
418 this.trigger( "volumechange" ); |
|
419 } |
|
420 |
|
421 return this.playerFns.getMute(); |
|
422 } else { |
|
423 return this.playerFns.getMute(); |
|
424 } |
|
425 }; |
|
426 |
|
427 IriSP.PopcornReplacement.player.prototype.volume = function(val) { |
|
428 if (typeof this.playerFns.getVolume == "undefined" || typeof this.playerFns.setVolume == "undefined") { |
|
429 return false; |
|
430 } |
|
431 var _vol = this.playerFns.getVolume(); |
|
432 if (typeof(val) !== "undefined" && parseFloat(val) !== NaN) { |
|
433 val = Math.max(0, Math.min(1, val)); |
|
434 if (parseFloat(val) != parseFloat(_vol)) { |
|
435 this.playerFns.setVolume(val); |
|
436 this.trigger("volumechange"); |
|
437 _vol = this.playerFns.getVolume(); |
|
438 } |
|
439 } |
|
440 return _vol; |
|
441 }; |
|
442 |
|
443 IriSP.PopcornReplacement.player.prototype.mute = IriSP.PopcornReplacement.player.prototype.muted; |
|
444 |
|
445 IriSP.PopcornReplacement.player.prototype.code = function(options) { |
|
446 this.__codes.push(options); |
|
447 return this; |
|
448 }; |
|
449 |
|
450 /* called everytime the player updates itself |
|
451 (onTime event) |
|
452 */ |
|
453 |
|
454 IriSP.PopcornReplacement.player.prototype.__timeHandler = function(event) { |
|
455 var pos = event.position; |
|
456 |
|
457 var i = 0; |
|
458 for(i = 0; i < this.__codes.length; i++) { |
|
459 var c = this.__codes[i]; |
|
460 |
|
461 if (pos >= c.start && pos < c.end && |
|
462 pos - 1 <= c.start) { |
|
463 c.onStart(); |
|
464 } |
|
465 |
|
466 if (pos > c.start && pos > c.end && |
|
467 pos - 1 <= c.end) { |
|
468 c.onEnd(); |
|
469 } |
|
470 |
|
471 } |
|
472 |
|
473 this.trigger("timeupdate"); |
|
474 }; |
|
475 |
|
476 IriSP.PopcornReplacement.player.prototype.__seekHandler = function(event) { |
|
477 var i = 0; |
|
478 |
|
479 for(i = 0; i < this.__codes.length; i++) { |
|
480 var c = this.__codes[i]; |
|
481 |
|
482 if (event.position >= c.start && event.position < c.end) { |
|
483 c.onEnd(); |
|
484 } |
|
485 } |
|
486 |
|
487 for(i = 0; i < this.__codes.length; i++) { |
|
488 var c = this.__codes[i]; |
|
489 |
|
490 if (typeof(event.offset) === "undefined") |
|
491 event.offset = 0; |
|
492 |
|
493 if (event.offset >= c.start && event.offset < c.end) { |
|
494 c.onStart(); |
|
495 } |
|
496 |
|
497 } |
|
498 |
|
499 /* this signal sends as an extra argument the position in the video. |
|
500 As far as I know, this argument is not provided by popcorn */ |
|
501 this.trigger("seeked", event.offset); |
|
502 }; |
|
503 |
|
504 IriSP.PopcornReplacement.player.prototype.__playHandler = function(event) { |
|
505 this.media.paused = false; |
|
506 this.trigger("play"); |
|
507 }; |
|
508 |
|
509 IriSP.PopcornReplacement.player.prototype.__pauseHandler = function(event) { |
|
510 this.media.paused = true; |
|
511 this.trigger("pause"); |
|
512 }; |
|
513 |
|
514 IriSP.PopcornReplacement.player.prototype.roundTime = function() { |
|
515 var currentTime = this.currentTime(); |
|
516 return Math.round(currentTime); |
|
517 };/* model.js is where data is stored in a standard form, whatever the serializer */ |
|
518 |
|
519 IriSP.Model = { |
|
520 _SOURCE_STATUS_EMPTY : 0, |
|
521 _SOURCE_STATUS_WAITING : 1, |
|
522 _SOURCE_STATUS_READY : 2, |
|
523 _ID_AUTO_INCREMENT : 0, |
|
524 getUID : function() { |
|
525 return "autoid-" + (++this._ID_AUTO_INCREMENT); |
|
526 }, |
|
527 regexpFromTextOrArray : function(_textOrArray) { |
|
528 function escapeText(_text) { |
|
529 return _text.replace(/([\\\*\+\?\|\{\[\}\]\(\)\^\$\.\#\/])/gm, '\\$1'); |
|
530 } |
|
531 return new RegExp( '(' |
|
532 + ( |
|
533 typeof _textOrArray === "string" |
|
534 ? escapeText(_textOrArray) |
|
535 : IriSP._(_textOrArray).map(escapeText).join("|") |
|
536 ) |
|
537 + ')', |
|
538 'gim' |
|
539 ); |
|
540 }, |
|
541 isoToDate : function(_str) { |
|
542 // http://delete.me.uk/2005/03/iso8601.html |
|
543 var regexp = "([0-9]{4})(-([0-9]{2})(-([0-9]{2})(T([0-9]{2}):([0-9]{2})(:([0-9]{2})(\.([0-9]+))?)?(Z|(([-+])([0-9]{2}):([0-9]{2})))?)?)?)?"; |
|
544 var d = _str.match(new RegExp(regexp)); |
|
545 |
|
546 var offset = 0; |
|
547 var date = new Date(d[1], 0, 1); |
|
548 |
|
549 if (d[3]) { date.setMonth(d[3] - 1); } |
|
550 if (d[5]) { date.setDate(d[5]); } |
|
551 if (d[7]) { date.setHours(d[7]); } |
|
552 if (d[8]) { date.setMinutes(d[8]); } |
|
553 if (d[10]) { date.setSeconds(d[10]); } |
|
554 if (d[12]) { date.setMilliseconds(Number("0." + d[12]) * 1000); } |
|
555 if (d[14]) { |
|
556 offset = (Number(d[16]) * 60) + Number(d[17]); |
|
557 offset *= ((d[15] == '-') ? 1 : -1); |
|
558 } |
|
559 |
|
560 offset -= date.getTimezoneOffset(); |
|
561 time = (Number(date) + (offset * 60 * 1000)); |
|
562 var _res = new Date(); |
|
563 _res.setTime(Number(time)); |
|
564 return _res; |
|
565 }, |
|
566 dateToIso : function(d) { |
|
567 function pad(n){return n<10 ? '0'+n : n} |
|
568 return d.getUTCFullYear()+'-' |
|
569 + pad(d.getUTCMonth()+1)+'-' |
|
570 + pad(d.getUTCDate())+'T' |
|
571 + pad(d.getUTCHours())+':' |
|
572 + pad(d.getUTCMinutes())+':' |
|
573 + pad(d.getUTCSeconds())+'Z' |
|
574 } |
|
575 } |
|
576 |
|
577 /* |
|
578 * IriSP.Model.List is a class for a list of elements (e.g. annotations, medias, etc. that each have a distinct ID) |
|
579 */ |
|
580 IriSP.Model.List = function(_directory) { |
|
581 Array.call(this); |
|
582 this.directory = _directory; |
|
583 this.idIndex = []; |
|
584 if (typeof _directory == "undefined") { |
|
585 throw "Error : new IriSP.Model.List(directory): directory is undefined"; |
|
586 } |
|
587 } |
|
588 |
|
589 IriSP.Model.List.prototype = new Array(); |
|
590 |
|
591 IriSP.Model.List.prototype.getElement = function(_id) { |
|
592 var _index = IriSP._(this.idIndex).indexOf(_id); |
|
593 if (_index !== -1) { |
|
594 return this[_index]; |
|
595 } else { |
|
596 var _un = _id.replace(/.*:/); |
|
597 return IriSP._(this.idIndex).find(function(_i) { |
|
598 return _i.replace(/.*:/) === _un; |
|
599 }); |
|
600 } |
|
601 } |
|
602 |
|
603 IriSP.Model.List.prototype.hasId = function(_id) { |
|
604 return (IriSP._(this.idIndex).indexOf(_id) !== -1); |
|
605 } |
|
606 |
|
607 /* On recent browsers, forEach and map are defined and do what we want. |
|
608 * Otherwise, we'll use the Underscore.js functions |
|
609 */ |
|
610 if (typeof Array.prototype.forEach === "undefined") { |
|
611 IriSP.Model.List.prototype.forEach = function(_callback) { |
|
612 var _this = this; |
|
613 IriSP._(this).forEach(function(_value, _key) { |
|
614 _callback(_value, _key, _this); |
|
615 }); |
|
616 } |
|
617 } |
|
618 |
|
619 if (typeof Array.prototype.map === "undefined") { |
|
620 IriSP.Model.List.prototype.map = function(_callback) { |
|
621 var _this = this; |
|
622 return IriSP._(this).map(function(_value, _key) { |
|
623 return _callback(_value, _key, _this); |
|
624 }); |
|
625 } |
|
626 } |
|
627 |
|
628 /* We override Array's filter function because it doesn't return an IriSP.Model.List |
|
629 */ |
|
630 IriSP.Model.List.prototype.filter = function(_callback) { |
|
631 var _this = this, |
|
632 _res = new IriSP.Model.List(this.directory); |
|
633 _res.addElements(IriSP._(this).filter(function(_value, _key) { |
|
634 return _callback(_value, _key, _this); |
|
635 })); |
|
636 return _res; |
|
637 } |
|
638 |
|
639 IriSP.Model.List.prototype.slice = function(_start, _end) { |
|
640 var _res = new IriSP.Model.List(this.directory); |
|
641 _res.addElements(Array.prototype.slice.call(this, _start, _end)); |
|
642 return _res; |
|
643 } |
|
644 |
|
645 IriSP.Model.List.prototype.splice = function(_start, _end) { |
|
646 var _res = new IriSP.Model.List(this.directory); |
|
647 _res.addElements(Array.prototype.splice.call(this, _start, _end)); |
|
648 this.idIndex.splice(_start, _end); |
|
649 return _res; |
|
650 } |
|
651 |
|
652 /* Array has a sort function, but it's not as interesting as Underscore.js's sortBy |
|
653 * and won't return a new IriSP.Model.List |
|
654 */ |
|
655 IriSP.Model.List.prototype.sortBy = function(_callback) { |
|
656 var _this = this, |
|
657 _res = new IriSP.Model.List(this.directory); |
|
658 _res.addElements(IriSP._(this).sortBy(function(_value, _key) { |
|
659 return _callback(_value, _key, _this); |
|
660 })); |
|
661 return _res; |
|
662 } |
|
663 |
|
664 /* Title and Description are basic information for (almost) all element types, |
|
665 * here we can search by these criteria |
|
666 */ |
|
667 IriSP.Model.List.prototype.searchByTitle = function(_text) { |
|
668 var _rgxp = IriSP.Model.regexpFromTextOrArray(_text); |
|
669 return this.filter(function(_element) { |
|
670 return _rgxp.test(_element.title); |
|
671 }); |
|
672 } |
|
673 |
|
674 IriSP.Model.List.prototype.searchByDescription = function(_text) { |
|
675 var _rgxp = IriSP.Model.regexpFromTextOrArray(_text); |
|
676 return this.filter(function(_element) { |
|
677 return _rgxp.test(_element.description); |
|
678 }); |
|
679 } |
|
680 |
|
681 IriSP.Model.List.prototype.searchByTextFields = function(_text) { |
|
682 var _rgxp = IriSP.Model.regexpFromTextOrArray(_text); |
|
683 return this.filter(function(_element) { |
|
684 return _rgxp.test(_element.description) || _rgxp.test(_element.title); |
|
685 }); |
|
686 } |
|
687 |
|
688 IriSP.Model.List.prototype.getTitles = function() { |
|
689 return this.map(function(_el) { |
|
690 return _el.title; |
|
691 }); |
|
692 } |
|
693 |
|
694 IriSP.Model.List.prototype.addId = function(_id) { |
|
695 var _el = this.directory.getElement(_id) |
|
696 if (!this.hasId(_id) && typeof _el !== "undefined") { |
|
697 this.idIndex.push(_id); |
|
698 Array.prototype.push.call(this, _el); |
|
699 } |
|
700 } |
|
701 |
|
702 IriSP.Model.List.prototype.push = function(_el) { |
|
703 if (typeof _el === "undefined") { |
|
704 return; |
|
705 } |
|
706 var _index = (IriSP._(this.idIndex).indexOf(_el.id)); |
|
707 if (_index === -1) { |
|
708 this.idIndex.push(_el.id); |
|
709 Array.prototype.push.call(this, _el); |
|
710 } else { |
|
711 this[_index] = _el; |
|
712 } |
|
713 } |
|
714 |
|
715 IriSP.Model.List.prototype.addIds = function(_array) { |
|
716 var _l = _array.length, |
|
717 _this = this; |
|
718 IriSP._(_array).forEach(function(_id) { |
|
719 _this.addId(_id); |
|
720 }); |
|
721 } |
|
722 |
|
723 IriSP.Model.List.prototype.addElements = function(_array) { |
|
724 var _this = this; |
|
725 IriSP._(_array).forEach(function(_el) { |
|
726 _this.push(_el); |
|
727 }); |
|
728 } |
|
729 |
|
730 IriSP.Model.List.prototype.removeId = function(_id) { |
|
731 var _index = (IriSP._(this.idIndex).indexOf(_id)); |
|
732 if (_index !== -1) { |
|
733 this.splice(_index,1); |
|
734 } |
|
735 } |
|
736 |
|
737 IriSP.Model.List.prototype.removeElement = function(_el) { |
|
738 this.removeId(_el.id); |
|
739 } |
|
740 |
|
741 IriSP.Model.List.prototype.removeIds = function(_list) { |
|
742 var _this = this; |
|
743 IriSP._(_list).forEach(function(_id) { |
|
744 _this.removeId(_id); |
|
745 }); |
|
746 } |
|
747 |
|
748 IriSP.Model.List.prototype.removeElements = function(_list) { |
|
749 var _this = this; |
|
750 IriSP._(_list).forEach(function(_el) { |
|
751 _this.removeElement(_el); |
|
752 }); |
|
753 } |
|
754 |
|
755 /* A simple time management object, that helps converting millisecs to seconds and strings, |
|
756 * without the clumsiness of the original Date object. |
|
757 */ |
|
758 |
|
759 IriSP.Model.Time = function(_milliseconds) { |
|
760 this.milliseconds = parseInt(typeof _milliseconds !== "undefined" ? _milliseconds : 0); |
|
761 } |
|
762 |
|
763 IriSP.Model.Time.prototype.setSeconds = function(_seconds) { |
|
764 this.milliseconds = 1000 * _seconds; |
|
765 } |
|
766 |
|
767 IriSP.Model.Time.prototype.getSeconds = function() { |
|
768 return Math.floor(this.milliseconds / 1000); |
|
769 } |
|
770 |
|
771 IriSP.Model.Time.prototype.getHMS = function() { |
|
772 var _totalSeconds = Math.abs(this.getSeconds()); |
|
773 return { |
|
774 hours : Math.floor(_totalSeconds / 3600), |
|
775 minutes : (Math.floor(_totalSeconds / 60) % 60), |
|
776 seconds : _totalSeconds % 60 |
|
777 } |
|
778 } |
|
779 |
|
780 IriSP.Model.Time.prototype.valueOf = function() { |
|
781 return this.milliseconds; |
|
782 } |
|
783 |
|
784 IriSP.Model.Time.prototype.toString = function() { |
|
785 function pad(_n) { |
|
786 var _res = _n.toString(); |
|
787 while (_res.length < 2) { |
|
788 _res = '0' + _res; |
|
789 } |
|
790 return _res; |
|
791 } |
|
792 var _hms = this.getHMS(), |
|
793 _res = ''; |
|
794 if (_hms.hours) { |
|
795 _res += pad(_hms.hours) + ':' |
|
796 } |
|
797 _res += pad(_hms.minutes) + ':' + pad(_hms.seconds); |
|
798 return _res; |
|
799 } |
|
800 |
|
801 /* IriSP.Model.Reference handles references between elements |
|
802 */ |
|
803 |
|
804 IriSP.Model.Reference = function(_source, _idRef) { |
|
805 this.source = _source; |
|
806 if (typeof _idRef === "object") { |
|
807 this.isList = true; |
|
808 this.id = IriSP._(_idRef).map(function(_id) { |
|
809 return _source.getNamespaced(_id).fullname; |
|
810 }); |
|
811 } else { |
|
812 this.isList = false; |
|
813 this.id = _source.getNamespaced(_idRef).fullname; |
|
814 } |
|
815 this.refresh(); |
|
816 } |
|
817 |
|
818 IriSP.Model.Reference.prototype.refresh = function() { |
|
819 if (this.isList) { |
|
820 this.contents = new IriSP.Model.List(this.source.directory); |
|
821 this.contents.addIds(this.id); |
|
822 } else { |
|
823 this.contents = this.source.directory.getElement(this.id); |
|
824 } |
|
825 |
|
826 } |
|
827 |
|
828 IriSP.Model.Reference.prototype.getContents = function() { |
|
829 if (typeof this.contents === "undefined" || (this.isList && this.contents.length != this.id.length)) { |
|
830 this.refresh(); |
|
831 } |
|
832 return this.contents; |
|
833 } |
|
834 |
|
835 IriSP.Model.Reference.prototype.isOrHasId = function(_idRef) { |
|
836 if (this.isList) { |
|
837 return (IriSP._(this.id).indexOf(_idRef) !== -1) |
|
838 } else { |
|
839 return (this.id == _idRef); |
|
840 } |
|
841 } |
|
842 |
|
843 /* */ |
|
844 |
|
845 IriSP.Model.Element = function(_id, _source) { |
|
846 this.elementType = 'element'; |
|
847 if (typeof _source === "undefined") { |
|
848 return; |
|
849 } |
|
850 if (typeof _id === "undefined" || !_id) { |
|
851 _id = IriSP.Model.getUID(); |
|
852 } |
|
853 this.source = _source; |
|
854 this.namespacedId = _source.getNamespaced(_id) |
|
855 this.id = this.namespacedId.fullname; |
|
856 this.title = ""; |
|
857 this.description = ""; |
|
858 this.source.directory.addElement(this); |
|
859 } |
|
860 |
|
861 IriSP.Model.Element.prototype.toString = function() { |
|
862 return this.elementType + (this.elementType !== 'element' ? ', id=' + this.id + ', title="' + this.title + '"' : ''); |
|
863 } |
|
864 |
|
865 IriSP.Model.Element.prototype.setReference = function(_elementType, _idRef) { |
|
866 this[_elementType] = new IriSP.Model.Reference(this.source, _idRef); |
|
867 } |
|
868 |
|
869 IriSP.Model.Element.prototype.getReference = function(_elementType) { |
|
870 if (typeof this[_elementType] !== "undefined") { |
|
871 return this[_elementType].getContents(); |
|
872 } |
|
873 } |
|
874 |
|
875 IriSP.Model.Element.prototype.getRelated = function(_elementType, _global) { |
|
876 _global = (typeof _global !== "undefined" && _global); |
|
877 var _this = this; |
|
878 return this.source.getList(_elementType, _global).filter(function(_el) { |
|
879 var _ref = _el[_this.elementType]; |
|
880 return _ref.isOrHasId(_this.id); |
|
881 }); |
|
882 } |
|
883 |
|
884 /* */ |
|
885 |
|
886 IriSP.Model.Media = function(_id, _source) { |
|
887 IriSP.Model.Element.call(this, _id, _source); |
|
888 this.elementType = 'media'; |
|
889 this.duration = new IriSP.Model.Time(); |
|
890 this.video = ''; |
|
891 } |
|
892 |
|
893 IriSP.Model.Media.prototype = new IriSP.Model.Element(); |
|
894 |
|
895 IriSP.Model.Media.prototype.setDuration = function(_durationMs) { |
|
896 this.duration.milliseconds = _durationMs; |
|
897 } |
|
898 |
|
899 IriSP.Model.Media.prototype.getAnnotations = function() { |
|
900 return this.getRelated("annotation"); |
|
901 } |
|
902 |
|
903 /* */ |
|
904 |
|
905 IriSP.Model.Tag = function(_id, _source) { |
|
906 IriSP.Model.Element.call(this, _id, _source); |
|
907 this.elementType = 'tag'; |
|
908 } |
|
909 |
|
910 IriSP.Model.Tag.prototype = new IriSP.Model.Element(); |
|
911 |
|
912 IriSP.Model.Tag.prototype.getAnnotations = function() { |
|
913 return this.getRelated("annotation"); |
|
914 } |
|
915 |
|
916 /* */ |
|
917 |
|
918 IriSP.Model.AnnotationType = function(_id, _source) { |
|
919 IriSP.Model.Element.call(this, _id, _source); |
|
920 this.elementType = 'annotationType'; |
|
921 } |
|
922 |
|
923 IriSP.Model.AnnotationType.prototype = new IriSP.Model.Element(); |
|
924 |
|
925 IriSP.Model.AnnotationType.prototype.getAnnotations = function() { |
|
926 return this.getRelated("annotation"); |
|
927 } |
|
928 |
|
929 /* Annotation |
|
930 * */ |
|
931 |
|
932 IriSP.Model.Annotation = function(_id, _source) { |
|
933 IriSP.Model.Element.call(this, _id, _source); |
|
934 this.elementType = 'annotation'; |
|
935 this.begin = new IriSP.Model.Time(); |
|
936 this.end = new IriSP.Model.Time(); |
|
937 } |
|
938 |
|
939 IriSP.Model.Annotation.prototype = new IriSP.Model.Element(null); |
|
940 |
|
941 IriSP.Model.Annotation.prototype.setBegin = function(_beginMs) { |
|
942 this.begin.milliseconds = _beginMs; |
|
943 } |
|
944 |
|
945 IriSP.Model.Annotation.prototype.setEnd = function(_beginMs) { |
|
946 this.end.milliseconds = _beginMs; |
|
947 } |
|
948 |
|
949 IriSP.Model.Annotation.prototype.setMedia = function(_idRef) { |
|
950 this.setReference("media", _idRef); |
|
951 } |
|
952 |
|
953 IriSP.Model.Annotation.prototype.getMedia = function() { |
|
954 return this.getReference("media"); |
|
955 } |
|
956 |
|
957 IriSP.Model.Annotation.prototype.setAnnotationType = function(_idRef) { |
|
958 this.setReference("annotationType", _idRef); |
|
959 } |
|
960 |
|
961 IriSP.Model.Annotation.prototype.getAnnotationType = function() { |
|
962 return this.getReference("annotationType"); |
|
963 } |
|
964 |
|
965 IriSP.Model.Annotation.prototype.setTags = function(_idRefs) { |
|
966 this.setReference("tag", _idRefs); |
|
967 } |
|
968 |
|
969 IriSP.Model.Annotation.prototype.getTags = function() { |
|
970 return this.getReference("tag"); |
|
971 } |
|
972 |
|
973 IriSP.Model.Annotation.prototype.getTagTexts = function() { |
|
974 return this.getTags().getTitles(); |
|
975 } |
|
976 |
|
977 /* */ |
|
978 |
|
979 IriSP.Model.Source = function(_config) { |
|
980 this.status = IriSP.Model._SOURCE_STATUS_EMPTY; |
|
981 if (typeof _config !== "undefined") { |
|
982 var _this = this; |
|
983 IriSP._(_config).forEach(function(_v, _k) { |
|
984 _this[_k] = _v; |
|
985 }) |
|
986 this.callbackQueue = []; |
|
987 this.contents = {}; |
|
988 if (typeof this.namespace === "undefined") { |
|
989 this.namespace = "metadataplayer"; |
|
990 } else { |
|
991 if (typeof this.namespaceUrl === "undefined" && typeof this.url !== "undefined") { |
|
992 var _matches = this.url.match(/(^[^?&]+|[^?&][a-zA-Z0-9_%=?]+)/g), |
|
993 _url = _matches[0]; |
|
994 if (_matches.length > 1) { |
|
995 _matches = IriSP._(_matches.slice(1)).reject(function(_txt) { |
|
996 return /\?$/.test(_txt); |
|
997 }); |
|
998 } |
|
999 if (_matches.length > 0) { |
|
1000 _url += '?' + _matches.join('&'); |
|
1001 } |
|
1002 this.namespaceUrl = _url; |
|
1003 } |
|
1004 } |
|
1005 if (typeof this.namespaceUrl === "undefined") { |
|
1006 this.namespaceUrl = "http://ldt.iri.centrepompidou.fr/"; |
|
1007 } |
|
1008 this.directory.addNamespace(this.namespace, this.namespaceUrl); |
|
1009 this.get(); |
|
1010 } |
|
1011 } |
|
1012 |
|
1013 IriSP.Model.Source.prototype.getNamespaced = function(_id) { |
|
1014 var _tab = _id.split(':'); |
|
1015 if (_tab.length > 1) { |
|
1016 return { |
|
1017 namespace : _tab[0], |
|
1018 name : _tab[1], |
|
1019 fullname : _id |
|
1020 } |
|
1021 } else { |
|
1022 return { |
|
1023 namespace : this.namespace, |
|
1024 name : _id, |
|
1025 fullname : this.namespace + ':' + _id |
|
1026 } |
|
1027 } |
|
1028 } |
|
1029 |
|
1030 IriSP.Model.Source.prototype.unNamespace = function(_id) { |
|
1031 if (typeof _id !== "undefined") { |
|
1032 return _id.replace(this.namespace + ':', ''); |
|
1033 } |
|
1034 } |
|
1035 |
|
1036 IriSP.Model.Source.prototype.addList = function(_listId, _contents) { |
|
1037 if (typeof this.contents[_listId] === "undefined") { |
|
1038 this.contents[_listId] = new IriSP.Model.List(this.directory); |
|
1039 } |
|
1040 this.contents[_listId].addElements(_contents); |
|
1041 } |
|
1042 |
|
1043 IriSP.Model.Source.prototype.getList = function(_listId, _global) { |
|
1044 _global = (typeof _global !== "undefined" && _global); |
|
1045 if (_global || typeof this.contents[_listId] === "undefined") { |
|
1046 return this.directory.getGlobalList().filter(function(_e) { |
|
1047 return (_e.elementType === _listId); |
|
1048 }); |
|
1049 } else { |
|
1050 return this.contents[_listId]; |
|
1051 } |
|
1052 } |
|
1053 |
|
1054 IriSP.Model.Source.prototype.forEach = function(_callback) { |
|
1055 var _this = this; |
|
1056 IriSP._(this.contents).forEach(function(_value, _key) { |
|
1057 _callback.call(_this, _value, _key); |
|
1058 }) |
|
1059 } |
|
1060 |
|
1061 IriSP.Model.Source.prototype.getElement = function(_elId) { |
|
1062 return this.directory.getElement(this.getNamespaced(_elId).fullname); |
|
1063 } |
|
1064 |
|
1065 IriSP.Model.Source.prototype.setCurrentMediaId = function(_idRef) { |
|
1066 if (typeof _idRef !== "undefined") { |
|
1067 this.currentMedia = this.getMedias().getElement(this.getNamespaced(_idRef).fullname); |
|
1068 } |
|
1069 } |
|
1070 |
|
1071 IriSP.Model.Source.prototype.setDefaultCurrentMedia = function() { |
|
1072 if (typeof this.currentMedia === "undefined" && this.getMedias().length) { |
|
1073 this.currentMedia = this.getMedias()[0]; |
|
1074 } |
|
1075 } |
|
1076 |
|
1077 IriSP.Model.Source.prototype.listNamespaces = function(_excludeSelf) { |
|
1078 var _this = this, |
|
1079 _nsls = [], |
|
1080 _excludeSelf = (typeof _excludeSelf !== "undefined" && _excludeSelf); |
|
1081 this.forEach(function(_list) { |
|
1082 IriSP._(_list).forEach(function(_el) { |
|
1083 var _ns = _el.id.replace(/:.*$/,''); |
|
1084 if (IriSP._(_nsls).indexOf(_ns) === -1 && (!_excludeSelf || _ns !== _this.namespace)) { |
|
1085 _nsls.push(_ns); |
|
1086 } |
|
1087 }) |
|
1088 }); |
|
1089 return _nsls; |
|
1090 } |
|
1091 |
|
1092 IriSP.Model.Source.prototype.get = function() { |
|
1093 this.status = IriSP.Model._SOURCE_STATUS_WAITING; |
|
1094 this.handleCallbacks(); |
|
1095 } |
|
1096 |
|
1097 /* We defer the callbacks calls so they execute after the queue is cleared */ |
|
1098 IriSP.Model.Source.prototype.deferCallback = function(_callback) { |
|
1099 var _this = this; |
|
1100 IriSP._.defer(function() { |
|
1101 _callback.call(_this); |
|
1102 }); |
|
1103 } |
|
1104 |
|
1105 IriSP.Model.Source.prototype.handleCallbacks = function() { |
|
1106 this.status = IriSP.Model._SOURCE_STATUS_READY; |
|
1107 while (this.callbackQueue.length) { |
|
1108 this.deferCallback(this.callbackQueue.splice(0,1)[0]); |
|
1109 } |
|
1110 } |
|
1111 |
|
1112 IriSP.Model.Source.prototype.onLoad = function(_callback) { |
|
1113 if (this.status === IriSP.Model._SOURCE_STATUS_READY) { |
|
1114 this.deferCallback(_callback); |
|
1115 } else { |
|
1116 this.callbackQueue.push(_callback); |
|
1117 } |
|
1118 } |
|
1119 |
|
1120 IriSP.Model.Source.prototype.serialize = function() { |
|
1121 return this.serializer.serialize(this); |
|
1122 } |
|
1123 |
|
1124 IriSP.Model.Source.prototype.deSerialize = function(_data) { |
|
1125 this.serializer.deSerialize(_data, this); |
|
1126 } |
|
1127 |
|
1128 IriSP.Model.Source.prototype.getAnnotations = function(_global) { |
|
1129 _global = (typeof _global !== "undefined" && _global); |
|
1130 return this.getList("annotation", _global); |
|
1131 } |
|
1132 |
|
1133 IriSP.Model.Source.prototype.getMedias = function(_global) { |
|
1134 _global = (typeof _global !== "undefined" && _global); |
|
1135 return this.getList("media", _global); |
|
1136 } |
|
1137 |
|
1138 IriSP.Model.Source.prototype.getAnnotationTypes = function(_global) { |
|
1139 _global = (typeof _global !== "undefined" && _global); |
|
1140 return this.getList("annotationType", _global); |
|
1141 } |
|
1142 |
|
1143 IriSP.Model.Source.prototype.getAnnotationsByTypeTitle = function(_title, _global) { |
|
1144 _global = (typeof _global !== "undefined" && _global); |
|
1145 var _res = new IriSP.Model.List(this.directory), |
|
1146 _annTypes = this.getAnnotationTypes(_global).searchByTitle(_title); |
|
1147 _annTypes.forEach(function(_annType) { |
|
1148 _res.addElements(_annType.getAnnotations(_global)); |
|
1149 }) |
|
1150 return _res; |
|
1151 } |
|
1152 |
|
1153 IriSP.Model.Source.prototype.getDuration = function() { |
|
1154 var _m = this.currentMedia; |
|
1155 if (typeof _m !== "undefined") { |
|
1156 return this.currentMedia.duration; |
|
1157 } |
|
1158 } |
|
1159 |
|
1160 /* */ |
|
1161 |
|
1162 IriSP.Model.RemoteSource = function(_config) { |
|
1163 IriSP.Model.Source.call(this, _config); |
|
1164 } |
|
1165 |
|
1166 IriSP.Model.RemoteSource.prototype = new IriSP.Model.Source(); |
|
1167 |
|
1168 IriSP.Model.RemoteSource.prototype.get = function() { |
|
1169 this.status = IriSP.Model._SOURCE_STATUS_WAITING; |
|
1170 var _this = this; |
|
1171 this.serializer.loadData(this.url, function(_result) { |
|
1172 _this.deSerialize(_result); |
|
1173 _this.handleCallbacks(); |
|
1174 }); |
|
1175 } |
|
1176 |
|
1177 /* */ |
|
1178 |
|
1179 IriSP.Model.Directory = function() { |
|
1180 this.remoteSources = {}; |
|
1181 this.elements = {}; |
|
1182 this.namespaces = {}; |
|
1183 } |
|
1184 |
|
1185 IriSP.Model.Directory.prototype.addNamespace = function(_namespace, _url) { |
|
1186 this.namespaces[_namespace] = _url; |
|
1187 } |
|
1188 |
|
1189 IriSP.Model.Directory.prototype.remoteSource = function(_properties) { |
|
1190 var _config = IriSP._({ directory: this }).extend(_properties); |
|
1191 if (typeof this.remoteSources[_properties.url] === "undefined") { |
|
1192 this.remoteSources[_properties.url] = new IriSP.Model.RemoteSource(_config); |
|
1193 } |
|
1194 return this.remoteSources[_properties.url]; |
|
1195 } |
|
1196 |
|
1197 IriSP.Model.Directory.prototype.newLocalSource = function(_properties) { |
|
1198 var _config = IriSP._({ directory: this }).extend(_properties), |
|
1199 _res = new IriSP.Model.Source(_config); |
|
1200 return _res; |
|
1201 } |
|
1202 |
|
1203 IriSP.Model.Directory.prototype.getElement = function(_id) { |
|
1204 var _res = this.elements[_id]; |
|
1205 if (typeof _res === "undefined") { |
|
1206 var _un = _id.replace(/.*:/), |
|
1207 _keys = IriSP._(this.elements).keys(); |
|
1208 _key = IriSP._(_keys).find(function(_i) { |
|
1209 return _i.replace(/.*:/) === _un; |
|
1210 }); |
|
1211 if (typeof _key !== "undefined") { |
|
1212 _res = this.elements[_key]; |
|
1213 } |
|
1214 } |
|
1215 return _res; |
|
1216 } |
|
1217 |
|
1218 IriSP.Model.Directory.prototype.addElement = function(_element) { |
|
1219 this.elements[_element.id] = _element; |
|
1220 } |
|
1221 |
|
1222 IriSP.Model.Directory.prototype.getGlobalList = function() { |
|
1223 var _res = new IriSP.Model.List(this); |
|
1224 _res.addIds(IriSP._(this.elements).keys()); |
|
1225 return _res; |
|
1226 } |
|
1227 |
|
1228 /* */ |
|
1229 IriSP.language = 'en'; |
|
1230 |
|
1231 IriSP.libFiles = { |
|
1232 defaultDir : "js/libs/", |
|
1233 inDefaultDir : { |
|
1234 underscore : "underscore-min.js", |
|
1235 Mustache : "mustache.js", |
|
1236 jQuery : "jquery.min.js", |
|
1237 jQueryUI : "jquery-ui.min.js", |
|
1238 swfObject : "swfobject.js", |
|
1239 cssjQueryUI : "jquery-ui.css", |
|
1240 popcorn : "popcorn.js", |
|
1241 jwplayer : "jwplayer.js", |
|
1242 raphael : "raphael-min.js", |
|
1243 "popcorn.mediafragment" : "popcorn.mediafragment.js", |
|
1244 "popcorn.code" : "popcorn.code.js", |
|
1245 "popcorn.jwplayer" : "popcorn.jwplayer.js", |
|
1246 "popcorn.youtube" : "popcorn.youtube.js", |
|
1247 tracemanager : "tracemanager.js" |
|
1248 }, |
|
1249 locations : { |
|
1250 // use to define locations outside defautl_dir |
|
1251 }, |
|
1252 cdn : { |
|
1253 jQueryUI : "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.17/jquery-ui.js", |
|
1254 swfObject : "http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js", |
|
1255 cssjQueryUI : "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.4/themes/base/jquery-ui.css" |
|
1256 }, |
|
1257 useCdn : false |
|
1258 } |
|
1259 |
|
1260 IriSP.widgetsDir = 'widgets'; |
|
1261 |
|
1262 IriSP.widgetsRequirements = { |
|
1263 Sparkline: { |
|
1264 noCss: true, |
|
1265 requires: "raphael" |
|
1266 }, |
|
1267 Arrow: { |
|
1268 noCss: true, |
|
1269 requires: "raphael" |
|
1270 }, |
|
1271 Mediafragment: { |
|
1272 noCss: true |
|
1273 }, |
|
1274 Trace : { |
|
1275 noCss: true, |
|
1276 requires: "tracemanager" |
|
1277 } |
|
1278 } |
|
1279 |
|
1280 IriSP.guiDefaults = { |
|
1281 width : 640, |
|
1282 container : 'LdtPlayer', |
|
1283 spacer_div_height : 0 |
|
1284 } |
|
1285 /* Definition of an ancestor for the Widget classes */ |
|
1286 |
|
1287 if (typeof IriSP.Widgets === "undefined") { |
|
1288 IriSP.Widgets = {} |
|
1289 } |
|
1290 |
|
1291 /** |
|
1292 * @class IriSP.Widget is an "abstract" class. It's mostly used to define some properties common to every widget. |
|
1293 * |
|
1294 * Note that widget constructors are never called directly by the user. Instead, the widgets are instantiated by functions |
|
1295 * defined in init.js |
|
1296 * |
|
1297 * @constructor |
|
1298 * @param player - a reference to the player widget |
|
1299 * @param config - configuration options for the widget |
|
1300 */ |
|
1301 |
|
1302 |
|
1303 IriSP.Widgets.Widget = function(player, config) { |
|
1304 |
|
1305 if( typeof player === "undefined") { |
|
1306 /* Probably an abstract call of the class when |
|
1307 * individual widgets set their prototype */ |
|
1308 return; |
|
1309 } |
|
1310 |
|
1311 /* Setting all the configuration options */ |
|
1312 var _type = config.type, |
|
1313 _config = IriSP._.defaults({}, config, player.config.gui.default_options, this.defaults), |
|
1314 _this = this; |
|
1315 |
|
1316 IriSP._(_config).forEach(function(_value, _key) { |
|
1317 _this[_key] = _value; |
|
1318 }); |
|
1319 |
|
1320 if (typeof this.width === "undefined") { |
|
1321 this.width = player.config.gui.width; |
|
1322 } |
|
1323 |
|
1324 /* Setting this.player at the end in case it's been overriden |
|
1325 * by a configuration option of the same name :-( |
|
1326 */ |
|
1327 this.player = player; |
|
1328 |
|
1329 /* Getting metadata */ |
|
1330 this.source = player.loadMetadata(this.metadata); |
|
1331 |
|
1332 /* Call draw when loaded */ |
|
1333 this.source.onLoad(function() { |
|
1334 _this.draw(); |
|
1335 }); |
|
1336 |
|
1337 /* Adding classes and html attributes */ |
|
1338 this.$ = IriSP.jQuery('#' + this.container); |
|
1339 this.$.addClass("Ldt-TraceMe Ldt-Widget").attr("widget-type", _type); |
|
1340 |
|
1341 /* Does the widget require other widgets ? */ |
|
1342 if (typeof this.requires !== "undefined") { |
|
1343 for (var _i = 0; _i < this.requires.length; _i++) { |
|
1344 var _subconfig = this.requires[_i]; |
|
1345 _subconfig.container = IriSP._.uniqueId(this.container + '_' + _subconfig.type + '_'); |
|
1346 this.$.append(IriSP.jQuery('<div>').attr("id",_subconfig.container)); |
|
1347 this.player.loadWidget(_subconfig, function(_widget) { |
|
1348 _this[_subconfig.type.replace(/^./,function(_s){return _s.toLowerCase();})] = _widget |
|
1349 }); |
|
1350 } |
|
1351 } |
|
1352 |
|
1353 this.l10n = (typeof this.messages[IriSP.language] !== "undefined" ? this.messages[IriSP.language] : this.messages["en"]); |
|
1354 |
|
1355 }; |
|
1356 |
|
1357 IriSP.Widgets.Widget.prototype.defaults = {} |
|
1358 |
|
1359 IriSP.Widgets.Widget.prototype.template = ''; |
|
1360 |
|
1361 IriSP.Widgets.Widget.prototype.messages = {"en":{}}; |
|
1362 |
|
1363 IriSP.Widgets.Widget.prototype.templateToHtml = function(_template) { |
|
1364 return Mustache.to_html(_template, this); |
|
1365 } |
|
1366 |
|
1367 IriSP.Widgets.Widget.prototype.renderTemplate = function() { |
|
1368 this.$.append(this.templateToHtml(this.template)); |
|
1369 } |
|
1370 |
|
1371 IriSP.Widgets.Widget.prototype.functionWrapper = function(_name) { |
|
1372 var _this = this, |
|
1373 _function = this[_name]; |
|
1374 if (typeof _function !== "undefined") { |
|
1375 return function() { |
|
1376 return _function.apply(_this, Array.prototype.slice.call(arguments, 0)); |
|
1377 } |
|
1378 } else { |
|
1379 console.log("Error, Unknown function IriSP." + this.type + "." + _name) |
|
1380 } |
|
1381 } |
|
1382 |
|
1383 IriSP.Widgets.Widget.prototype.bindPopcorn = function(_popcornEvent, _functionName) { |
|
1384 this.player.popcorn.listen(_popcornEvent, this.functionWrapper(_functionName)) |
|
1385 } |
|
1386 |
|
1387 IriSP.Widgets.Widget.prototype.getWidgetAnnotations = function() { |
|
1388 return typeof this.annotation_type !== "undefined" && this.annotation_type ? this.source.getAnnotationsByTypeTitle(this.annotation_type) : this.source.getAnnotations(); |
|
1389 } |
|
1390 |
|
1391 /** |
|
1392 * This method responsible of drawing a widget on screen. |
|
1393 */ |
|
1394 IriSP.Widgets.Widget.prototype.draw = function() { |
|
1395 /* implemented by "sub-classes" */ |
|
1396 }; |
|
1397 /** |
|
1398 * Optional method if you want your widget to support redraws. |
|
1399 */ |
|
1400 IriSP.Widgets.Widget.prototype.redraw = function() { |
|
1401 /* implemented by "sub-classes" */ |
|
1402 }; |
|
1403 /* To wrap a player the develop should create a new class derived from |
|
1404 the IriSP.PopcornReplacement.player and defining the correct functions */ |
|
1405 |
|
1406 /** allocine player wrapper */ |
|
1407 IriSP.PopcornReplacement.allocine = function(container, options) { |
|
1408 // console.log("Calling allocine player"); |
|
1409 /* appel du parent pour initialiser les structures communes à tous les players */ |
|
1410 IriSP.PopcornReplacement.player.call(this, container, options); |
|
1411 |
|
1412 var _this = this; |
|
1413 |
|
1414 /* Définition des fonctions de l'API - */ |
|
1415 |
|
1416 this.playerFns = { |
|
1417 play : function() { |
|
1418 return _this.apiCall("play"); |
|
1419 }, |
|
1420 pause : function() { |
|
1421 return _this.apiCall("pause"); |
|
1422 }, |
|
1423 getPosition : function() { |
|
1424 return _this.apiCall("getSeek","return") || 0; |
|
1425 }, |
|
1426 seek : function(pos) { |
|
1427 return _this.apiCall("seek",pos); |
|
1428 }, |
|
1429 getMute : function() { |
|
1430 return _this.apiCall("getMute","return"); |
|
1431 }, |
|
1432 setMute : function(p) { |
|
1433 return _this.apiCall("setMute", p); |
|
1434 } |
|
1435 } |
|
1436 |
|
1437 window.onReady = IriSP.wrap(this, this.ready); |
|
1438 window.onAllocineStateChange = IriSP.wrap(this, this.stateHandler); |
|
1439 window.onTime = IriSP.wrap(this, this.progressHandler); |
|
1440 |
|
1441 var _flashVars = { |
|
1442 "streamFMS" : true, |
|
1443 "adVast" : false, |
|
1444 "lg" : "fr_cinecast", |
|
1445 "autoPlay" : options.autoPlay, |
|
1446 "directVideoTitle" : "", |
|
1447 "urlAcData" : options.urlAcData, |
|
1448 "directVideoPath" : options.video, |
|
1449 "host" : "http://allocine.fr" |
|
1450 } |
|
1451 |
|
1452 if (typeof IriSP.__jsonMetadata["medias"][0].meta == "object" && typeof IriSP.__jsonMetadata["medias"][0].meta.subtitles == "string") { |
|
1453 _flashVars.subTitlePath = IriSP.__jsonMetadata["medias"][0].meta.subtitles; |
|
1454 } |
|
1455 |
|
1456 |
|
1457 var params = { |
|
1458 "allowScriptAccess" : "always", |
|
1459 "wmode": "opaque", |
|
1460 "flashvars" : IriSP.jQuery.param(_flashVars), |
|
1461 "allowfullscreen" : true |
|
1462 }; |
|
1463 var atts = { |
|
1464 id : this.container |
|
1465 }; |
|
1466 swfobject.embedSWF(options.acPlayerUrl, this.container, options.width, options.height, "10", null, null, params, atts); |
|
1467 |
|
1468 }; |
|
1469 |
|
1470 IriSP.PopcornReplacement.allocine.prototype = new IriSP.PopcornReplacement.player("", {}); |
|
1471 |
|
1472 IriSP.PopcornReplacement.allocine.prototype.ready = function() { |
|
1473 this.player = document.getElementById(this.container); |
|
1474 this.player.addEventListener("onStateChange", "onAllocineStateChange"); |
|
1475 this.player.cueVideoByUrl(this._options.video); |
|
1476 this.callbacks.onReady(); |
|
1477 }; |
|
1478 |
|
1479 IriSP.PopcornReplacement.allocine.prototype.progressHandler = function(progressInfo) { |
|
1480 this.callbacks.onTime({ |
|
1481 position: progressInfo.mediaTime |
|
1482 }); |
|
1483 } |
|
1484 |
|
1485 |
|
1486 IriSP.PopcornReplacement.allocine.prototype.apiCall = function(_method, _arg) { |
|
1487 if (this.player) { |
|
1488 try { |
|
1489 if (typeof _arg == "undefined") { |
|
1490 return this.player.sendToActionScript(_method); |
|
1491 } else { |
|
1492 return this.player.sendToActionScript(_method, _arg); |
|
1493 } |
|
1494 } catch(e) { |
|
1495 console.error('Exception while requesting AcPlayer for "' + _method + (typeof _arg == "undefined" ? '' : '" with argument "' + _arg ) + '"\n', e); |
|
1496 return false; |
|
1497 } |
|
1498 } else { |
|
1499 return false; |
|
1500 } |
|
1501 } |
|
1502 |
|
1503 IriSP.PopcornReplacement.allocine.prototype.stateHandler = function(state) { |
|
1504 console.log("stateHandler"); |
|
1505 switch(state) { |
|
1506 case 1: |
|
1507 this.callbacks.onPlay(); |
|
1508 break; |
|
1509 |
|
1510 case 2: |
|
1511 this.callbacks.onPause(); |
|
1512 break; |
|
1513 |
|
1514 case 3: |
|
1515 this.callbacks.onSeek({ |
|
1516 position: this.player.getCurrentTime() |
|
1517 }); |
|
1518 break; |
|
1519 |
|
1520 /* |
|
1521 case 5: |
|
1522 this.callbacks.onReady(); |
|
1523 break; |
|
1524 */ |
|
1525 } |
|
1526 |
|
1527 };/* To wrap a player the develop should create a new class derived from |
|
1528 the IriSP.PopcornReplacement.player and defining the correct functions */ |
|
1529 |
|
1530 /** jwplayer player wrapper */ |
|
1531 IriSP.PopcornReplacement.dailymotion = function(container, options) { |
|
1532 console.log("Calling"); |
|
1533 /* appel du parent pour initialiser les structures communes à tous les players */ |
|
1534 IriSP.PopcornReplacement.player.call(this, container, options); |
|
1535 |
|
1536 var _this = this; |
|
1537 |
|
1538 /* Définition des fonctions de l'API - */ |
|
1539 |
|
1540 this.playerFns = { |
|
1541 play : function() { |
|
1542 if (_this.player) { |
|
1543 return _this.player.playVideo(); |
|
1544 } else { |
|
1545 return false; |
|
1546 } |
|
1547 }, |
|
1548 pause : function() { |
|
1549 if (_this.player) { |
|
1550 return _this.player.pauseVideo(); |
|
1551 } else { |
|
1552 return false; |
|
1553 } |
|
1554 }, |
|
1555 getPosition : function() { |
|
1556 if (_this.player) { |
|
1557 return _this.player.getCurrentTime(); |
|
1558 } else { |
|
1559 return 0; |
|
1560 } |
|
1561 }, |
|
1562 seek : function(pos) { |
|
1563 if (_this.player) { |
|
1564 return _this.player.seekTo(pos); |
|
1565 } else { |
|
1566 return false; |
|
1567 } |
|
1568 }, |
|
1569 getMute : function() { |
|
1570 if (_this.player) { |
|
1571 return _this.player.isMuted(); |
|
1572 } else { |
|
1573 return false; |
|
1574 } |
|
1575 }, |
|
1576 setMute : function(p) { |
|
1577 if (_this.player) { |
|
1578 if (p) { |
|
1579 _this.player.mute(); |
|
1580 } |
|
1581 else { |
|
1582 _this.player.unMute(); |
|
1583 } |
|
1584 } |
|
1585 }, |
|
1586 getVolume : function() { |
|
1587 if (_this.player) { |
|
1588 return _this.player.getVolume() / 100; |
|
1589 } else { |
|
1590 return false; |
|
1591 } |
|
1592 }, |
|
1593 setVolume : function(p) { |
|
1594 if (_this.player) { |
|
1595 _this.player.setVolume(Math.floor(100 * p)); |
|
1596 } |
|
1597 }, |
|
1598 } |
|
1599 |
|
1600 window.onDailymotionPlayerReady = IriSP.wrap(this, this.ready); |
|
1601 window.onDailymotionStateChange = IriSP.wrap(this, this.stateHandler); |
|
1602 window.onDailymotionVideoProgress = IriSP.wrap(this, this.progressHandler); |
|
1603 |
|
1604 var params = { |
|
1605 "allowScriptAccess" : "always", |
|
1606 "wmode": "opaque" |
|
1607 }; |
|
1608 var atts = { |
|
1609 id : this.container |
|
1610 }; |
|
1611 swfobject.embedSWF("http://www.dailymotion.com/swf?chromeless=1&enableApi=1", this.container, options.width, options.height, "8", null, null, params, atts); |
|
1612 |
|
1613 }; |
|
1614 |
|
1615 IriSP.PopcornReplacement.dailymotion.prototype = new IriSP.PopcornReplacement.player("", {}); |
|
1616 |
|
1617 IriSP.PopcornReplacement.dailymotion.prototype.ready = function() { |
|
1618 |
|
1619 this.player = document.getElementById(this.container); |
|
1620 |
|
1621 this.player.addEventListener("onStateChange", "onDailymotionStateChange"); |
|
1622 this.player.addEventListener("onVideoProgress", "onDailymotionVideoProgress"); |
|
1623 this.player.cueVideoByUrl(this._options.video); |
|
1624 |
|
1625 this.callbacks.onReady(); |
|
1626 }; |
|
1627 |
|
1628 IriSP.PopcornReplacement.dailymotion.prototype.progressHandler = function(progressInfo) { |
|
1629 |
|
1630 this.callbacks.onTime({ |
|
1631 position: progressInfo.mediaTime |
|
1632 }); |
|
1633 } |
|
1634 |
|
1635 IriSP.PopcornReplacement.dailymotion.prototype.stateHandler = function(state) { |
|
1636 |
|
1637 switch(state) { |
|
1638 case 1: |
|
1639 this.callbacks.onPlay(); |
|
1640 break; |
|
1641 |
|
1642 case 2: |
|
1643 this.callbacks.onPause(); |
|
1644 break; |
|
1645 |
|
1646 case 3: |
|
1647 this.callbacks.onSeek({ |
|
1648 position: this.player.getCurrentTime() |
|
1649 }); |
|
1650 break; |
|
1651 |
|
1652 /* |
|
1653 case 5: |
|
1654 this.callbacks.onReady(); |
|
1655 break; |
|
1656 */ |
|
1657 } |
|
1658 |
|
1659 };/* To wrap a player the develop should create a new class derived from |
|
1660 the IriSP.PopcornReplacement.player and defining the correct functions */ |
|
1661 |
|
1662 /** jwplayer player wrapper */ |
|
1663 IriSP.PopcornReplacement.jwplayer = function(container, options) { |
|
1664 /* appel du parent pour initialiser les structures communes à tous les players */ |
|
1665 IriSP.PopcornReplacement.player.call(this, container, options); |
|
1666 |
|
1667 this.media.duration = options.duration; /* optional */ |
|
1668 |
|
1669 /* Définition des fonctions de l'API - */ |
|
1670 this.playerFns = { |
|
1671 play: function() { return jwplayer(this.container).play(); }, |
|
1672 pause: function() { return jwplayer(this.container).pause(); }, |
|
1673 getPosition: function() { return jwplayer(this.container).getPosition(); }, |
|
1674 seek: function(pos) { return jwplayer(this.container).seek(pos); }, |
|
1675 getMute: function() { return jwplayer(this.container).getMute() }, |
|
1676 setMute: function(p) { return jwplayer(this.container).setMute(p); }, |
|
1677 getVolume: function() { return jwplayer(this.container).getVolume() / 100; }, |
|
1678 setVolume: function(p) { return jwplayer(this.container).setVolume(Math.floor(100*p)); } |
|
1679 } |
|
1680 |
|
1681 options.events = this.callbacks; |
|
1682 |
|
1683 jwplayer(this.container).setup(options); |
|
1684 }; |
|
1685 |
|
1686 IriSP.PopcornReplacement.jwplayer.prototype = new IriSP.PopcornReplacement.player("", {}); |
|
1687 /* Cinecast Cinelab Serializer */ |
|
1688 |
|
1689 if (typeof IriSP.serializers === "undefined") { |
|
1690 IriSP.serializers = {} |
|
1691 } |
|
1692 |
|
1693 IriSP.serializers.cinecast = { |
|
1694 types : { |
|
1695 media : { |
|
1696 serialized_name : "medias", |
|
1697 model_name : "media", |
|
1698 deserializer : function(_data, _source) { |
|
1699 var _res = new IriSP.Model.Media(_data.id, _source); |
|
1700 _res.video = _data.url; |
|
1701 _res.title = _data.meta.title; |
|
1702 _res.description = _data.meta.synopsis; |
|
1703 _res.setDuration(_data.meta.duration); |
|
1704 return _res; |
|
1705 }, |
|
1706 serializer : function(_data, _source) { |
|
1707 return { |
|
1708 id : _source.unNamespace(_data.id), |
|
1709 url : _data.video, |
|
1710 meta : { |
|
1711 title : _data.title, |
|
1712 synopsis : _data.description, |
|
1713 duration : _data.duration.milliseconds |
|
1714 } |
|
1715 } |
|
1716 } |
|
1717 }, |
|
1718 tag : { |
|
1719 serialized_name : "tags", |
|
1720 model_name : "tag", |
|
1721 deserializer : function(_data, _source) { |
|
1722 var _res = new IriSP.Model.Tag(_data.id, _source); |
|
1723 _res.title = _data.meta.description; |
|
1724 return _res; |
|
1725 }, |
|
1726 serializer : function(_data, _source) { |
|
1727 return { |
|
1728 id : _source.unNamespace(_data.id), |
|
1729 meta : { |
|
1730 description : _data.title |
|
1731 } |
|
1732 } |
|
1733 } |
|
1734 }, |
|
1735 annotationType : { |
|
1736 serialized_name : "annotation_types", |
|
1737 deserializer : function(_data, _source) { |
|
1738 var _res = new IriSP.Model.AnnotationType(_data.id, _source); |
|
1739 _res.title = _source.getNamespaced(_data.id).name; |
|
1740 _res.description = _data.meta.description; |
|
1741 return _res; |
|
1742 }, |
|
1743 serializer : function(_data, _source) { |
|
1744 return { |
|
1745 id : _source.unNamespace(_data.id), |
|
1746 meta : { |
|
1747 description : _data.description |
|
1748 } |
|
1749 } |
|
1750 } |
|
1751 }, |
|
1752 annotation : { |
|
1753 serialized_name : "annotations", |
|
1754 deserializer : function(_data, _source) { |
|
1755 var _res = new IriSP.Model.Annotation(_data.id, _source); |
|
1756 _res.title = _data.meta.creator_name; |
|
1757 _res.description = _data.content.data; |
|
1758 _res.created = IriSP.Model.isoToDate(_data.meta.created); |
|
1759 _res.setMedia(_data.media, _source); |
|
1760 _res.setAnnotationType(_data.type); |
|
1761 _res.setTags(IriSP._(_data.tags).map(function(_t) { |
|
1762 if (typeof _source.contents.tag === "undefined") { |
|
1763 _source.contents.tag = new IriSP.Model.List(_source.directory); |
|
1764 } |
|
1765 if (_source.contents.tag.hasId(_t)) { |
|
1766 return _t; |
|
1767 } else { |
|
1768 var _id = _t.toLowerCase() |
|
1769 .replace(/#/g,'') |
|
1770 .replace(/^(\d)/,'_$1') |
|
1771 .replace(/[áâäà ã]/g,'a') |
|
1772 .replace(/ç/g,'c') |
|
1773 .replace(/[éèêë]/g,'e') |
|
1774 .replace(/[Ãìîï]/g,'i') |
|
1775 .replace(/ñ/g,'n') |
|
1776 .replace(/[óòôöõ]/g,'o') |
|
1777 .replace(/Å“/g,'oe') |
|
1778 .replace(/[úùûü]/g,'u') |
|
1779 .replace(/ÿ/g,'y') |
|
1780 .replace(/[^A-Za-z0-9_]/g,''), |
|
1781 _tag = new IriSP.Model.Tag(_id, _source); |
|
1782 _tag.title = _t; |
|
1783 _source.contents.tag.push(_tag); |
|
1784 return _id; |
|
1785 } |
|
1786 })); |
|
1787 _res.setBegin(_data.begin); |
|
1788 _res.setEnd(_data.end); |
|
1789 _res.creator = _data.meta.creator; |
|
1790 return _res; |
|
1791 }, |
|
1792 serializer : function(_data, _source) { |
|
1793 return { |
|
1794 id : _source.unNamespace(_data.id), |
|
1795 content : { |
|
1796 data : _data.description |
|
1797 }, |
|
1798 begin : _data.begin.milliseconds, |
|
1799 end : _data.begin.milliseconds, |
|
1800 media : _source.unNamespace(_data.media.id), |
|
1801 type : _source.unNamespace(_data.annotationType.id), |
|
1802 meta : { |
|
1803 created : IriSP.Model.dateToIso(_data.created), |
|
1804 creator : _data.creator, |
|
1805 creator_name : _data.title |
|
1806 }, |
|
1807 tags : _data.tag.id.map(function(_id) { |
|
1808 return _source.unNamespace(_id) |
|
1809 }) |
|
1810 } |
|
1811 } |
|
1812 } |
|
1813 }, |
|
1814 serialize : function(_source) { |
|
1815 var _res = { |
|
1816 format : "http://advene.org/ns/cinelab/" |
|
1817 }, |
|
1818 _this = this, |
|
1819 _nsls = _source.listNamespaces(true); |
|
1820 _res.imports = []; |
|
1821 for (var _i = 0; _i < _nsls.length; _i++) { |
|
1822 if (typeof _source.directory.namespaces[_nsls[_i]] !== "undefined") { |
|
1823 _res.imports.push({ |
|
1824 id : _nsls[_i], |
|
1825 url : _source.directory.namespaces[_nsls[_i]] |
|
1826 }) |
|
1827 } |
|
1828 } |
|
1829 _source.forEach(function(_list, _typename) { |
|
1830 if (typeof _this.types[_typename] !== "undefined") { |
|
1831 _res[_this.types[_typename].serialized_name] = _list.map(function(_el) { |
|
1832 return _this.types[_typename].serializer(_el, _source); |
|
1833 }); |
|
1834 } |
|
1835 }); |
|
1836 return _res; |
|
1837 }, |
|
1838 loadData : function(_url, _callback) { |
|
1839 IriSP.jQuery.getJSON(_url, _callback) |
|
1840 }, |
|
1841 deSerialize : function(_data, _source) { |
|
1842 if (typeof _data !== "object" || _data === null) { |
|
1843 return; |
|
1844 } |
|
1845 if (typeof _data.imports !== "undefined") { |
|
1846 IriSP._(_data.imports).forEach(function(_import) { |
|
1847 _source.directory.namespaces[_import.id] = _import.url; |
|
1848 }) |
|
1849 } |
|
1850 IriSP._(this.types).forEach(function(_type, _typename) { |
|
1851 var _listdata = _data[_type.serialized_name]; |
|
1852 if (typeof _listdata !== "undefined" && _listdata !== null) { |
|
1853 var _list = new IriSP.Model.List(_source.directory); |
|
1854 if (_listdata.hasOwnProperty("length")) { |
|
1855 var _l = _listdata.length; |
|
1856 for (var _i = 0; _i < _l; _i++) { |
|
1857 _list.push(_type.deserializer(_listdata[_i], _source)); |
|
1858 } |
|
1859 } else { |
|
1860 _list.push(_type.deserializer(_listdata, _source)); |
|
1861 } |
|
1862 _source.addList(_typename, _list); |
|
1863 } |
|
1864 }); |
|
1865 |
|
1866 if (typeof _data.meta !== "undefined" && typeof _data.meta.main_media !== "undefined" && typeof _data.meta.main_media["id-ref"] !== "undefined") { |
|
1867 _source.setCurrentMediaId(_data.meta.id); |
|
1868 } |
|
1869 _source.setDefaultCurrentMedia(); |
|
1870 } |
|
1871 } |
|
1872 |
|
1873 /* LDT Platform Serializer */ |
|
1874 |
|
1875 if (typeof IriSP.serializers === "undefined") { |
|
1876 IriSP.serializers = {} |
|
1877 } |
|
1878 |
|
1879 IriSP.serializers.ldt = { |
|
1880 types : { |
|
1881 media : { |
|
1882 serialized_name : "medias", |
|
1883 model_name : "media", |
|
1884 deserializer : function(_data, _source) { |
|
1885 var _res = new IriSP.Model.Media(_data.id, _source); |
|
1886 _res.video = ( |
|
1887 typeof _data.url !== "undefined" |
|
1888 ? _data.url |
|
1889 : ( |
|
1890 typeof _data.href !== "undefined" |
|
1891 ? _data.href |
|
1892 : null |
|
1893 ) |
|
1894 ); |
|
1895 if (typeof _data.meta.item !== "undefined" && _data.meta.item.name === "streamer") { |
|
1896 _res.streamer = _data.meta.item.value; |
|
1897 } |
|
1898 _res.title = _data.meta["dc:title"]; |
|
1899 _res.description = _data.meta["dc:description"]; |
|
1900 _res.setDuration(_data.meta["dc:duration"]); |
|
1901 return _res; |
|
1902 }, |
|
1903 serializer : function(_data, _source) { |
|
1904 return { |
|
1905 id : _source.unNamespace(_data.id), |
|
1906 url : _data.video, |
|
1907 meta : { |
|
1908 "dc:title" : _data.title, |
|
1909 "dc:description" : _data.description, |
|
1910 "dc:duration" : _data.duration.milliseconds |
|
1911 } |
|
1912 } |
|
1913 } |
|
1914 }, |
|
1915 tag : { |
|
1916 serialized_name : "tags", |
|
1917 model_name : "tag", |
|
1918 deserializer : function(_data, _source) { |
|
1919 var _res = new IriSP.Model.Tag(_data.id, _source); |
|
1920 _res.title = _data.meta["dc:title"]; |
|
1921 return _res; |
|
1922 }, |
|
1923 serializer : function(_data, _source) { |
|
1924 return { |
|
1925 id : _source.unNamespace(_data.id), |
|
1926 meta : { |
|
1927 "dc:title" : _data.title |
|
1928 } |
|
1929 } |
|
1930 } |
|
1931 }, |
|
1932 annotationType : { |
|
1933 serialized_name : "annotation-types", |
|
1934 deserializer : function(_data, _source) { |
|
1935 var _res = new IriSP.Model.AnnotationType(_data.id, _source); |
|
1936 _res.title = _data["dc:title"]; |
|
1937 _res.description = _data["dc:description"]; |
|
1938 return _res; |
|
1939 }, |
|
1940 serializer : function(_data, _source) { |
|
1941 return { |
|
1942 id : _source.unNamespace(_data.id), |
|
1943 "dc:title" : _data.title, |
|
1944 "dc:description" : _data.description |
|
1945 } |
|
1946 } |
|
1947 }, |
|
1948 annotation : { |
|
1949 serialized_name : "annotations", |
|
1950 deserializer : function(_data, _source) { |
|
1951 var _res = new IriSP.Model.Annotation(_data.id, _source); |
|
1952 _res.title = _data.content.title || ""; |
|
1953 _res.description = _data.content.description || ""; |
|
1954 if (typeof _data.content.img !== "undefined" && _data.content.img.src !== "undefined") { |
|
1955 _res.thumbnail = _data.content.img.src; |
|
1956 } |
|
1957 _res.created = IriSP.Model.isoToDate(_data.meta["dc:created"]); |
|
1958 if (typeof _data.color !== "undefined") { |
|
1959 var _c = parseInt(_data.color).toString(16); |
|
1960 while (_c.length < 6) { |
|
1961 _c = '0' + _c; |
|
1962 } |
|
1963 _res.color = '#' + _c; |
|
1964 } |
|
1965 _res.setMedia(_data.media, _source); |
|
1966 _res.setAnnotationType(_data.meta["id-ref"]); |
|
1967 _res.setTags(IriSP._(_data.tags).pluck("id-ref")); |
|
1968 _res.setBegin(_data.begin); |
|
1969 _res.setEnd(_data.end); |
|
1970 _res.creator = _data.meta["dc:creator"] || ""; |
|
1971 _res.project = _data.meta.project || ""; |
|
1972 if (typeof _data.meta["dc:source"] !== "undefined" && typeof _data.meta["dc:source"].content !== "undefined") { |
|
1973 _res.source = JSON.parse(_data.meta["dc:source"].content); |
|
1974 } |
|
1975 return _res; |
|
1976 }, |
|
1977 serializer : function(_data, _source) { |
|
1978 return { |
|
1979 id : _source.unNamespace(_data.id), |
|
1980 content : { |
|
1981 title : _data.title, |
|
1982 description : _data.description |
|
1983 }, |
|
1984 media : _source.unNamespace(_data.media.id), |
|
1985 meta : { |
|
1986 "id-ref" : _source.unNamespace(_data.annotationType.id), |
|
1987 "dc:created" : IriSP.Model.dateToIso(_data.created), |
|
1988 "dc:creator" : _data.creator, |
|
1989 project : _source.projectId |
|
1990 }, |
|
1991 tags : IriSP._(_data.tag.id).map(function(_d) { |
|
1992 return { |
|
1993 "id-ref" : _source.unNamespace(_id) |
|
1994 } |
|
1995 }) |
|
1996 } |
|
1997 } |
|
1998 } |
|
1999 }, |
|
2000 serialize : function(_source) { |
|
2001 var _res = {}, |
|
2002 _this = this; |
|
2003 _source.forEach(function(_list, _typename) { |
|
2004 if (typeof _this.types[_typename] !== "undefined") { |
|
2005 _res[_this.types[_typename].serialized_name] = _list.map(function(_el) { |
|
2006 return _this.types[_typename].serializer(_el, _source); |
|
2007 }); |
|
2008 } |
|
2009 }); |
|
2010 return _res; |
|
2011 }, |
|
2012 loadData : function(_url, _callback) { |
|
2013 IriSP.jQuery.getJSON(_url, _callback) |
|
2014 }, |
|
2015 deSerialize : function(_data, _source) { |
|
2016 if (typeof _data !== "object" || _data === null) { |
|
2017 return; |
|
2018 } |
|
2019 IriSP._(this.types).forEach(function(_type, _typename) { |
|
2020 var _listdata = _data[_type.serialized_name]; |
|
2021 if (typeof _listdata !== "undefined" && _listdata !== null) { |
|
2022 var _list = new IriSP.Model.List(_source.directory); |
|
2023 if (_listdata.hasOwnProperty("length")) { |
|
2024 var _l = _listdata.length; |
|
2025 for (var _i = 0; _i < _l; _i++) { |
|
2026 _list.push(_type.deserializer(_listdata[_i], _source)); |
|
2027 } |
|
2028 } else { |
|
2029 _list.push(_type.deserializer(_listdata, _source)); |
|
2030 } |
|
2031 _source.addList(_typename, _list); |
|
2032 } |
|
2033 }); |
|
2034 |
|
2035 if (typeof _data.meta !== "undefined") { |
|
2036 _source.projectId = _data.meta.id; |
|
2037 } |
|
2038 |
|
2039 if (typeof _data.meta !== "undefined" && typeof _data.meta.main_media !== "undefined" && typeof _data.meta.main_media["id-ref"] !== "undefined") { |
|
2040 _source.setCurrentMediaId(_data.meta.main_media["id-ref"]); |
|
2041 } |
|
2042 _source.setDefaultCurrentMedia(); |
|
2043 } |
|
2044 } |
|
2045 |