| author | veltr |
| Tue, 17 Apr 2012 20:19:46 +0200 | |
| branch | new-model |
| changeset 868 | a525cc2214e7 |
| parent 866 | 3bf7aa8216e5 |
| child 870 | 2c025db10a10 |
| permissions | -rw-r--r-- |
| 123 | 1 |
/* init.js - initialization and configuration of Popcorn and the widgets |
2 |
exemple json configuration: |
|
| 531 | 3 |
*/ |
|
453
8568e47379a2
added autoconfiguration of the media source for rtmp streams.
hamidouk
parents:
430
diff
changeset
|
4 |
|
| 868 | 5 |
/* The Metadataplayer Object, single point of entry, replaces IriSP.init_player */ |
6 |
||
7 |
IriSP.Metadataplayer = function(config, video_metadata) { |
|
8 |
IriSP._.defaults(config.gui, IriSP.guiDefaults); |
|
9 |
var _container = document.getElementById(config.gui.container); |
|
10 |
_container.innerHTML = IriSP.templToHTML(IriSP.loading_template, config.gui); |
|
11 |
this.video_metadata = video_metadata; |
|
12 |
this.sourceManager = new IriSP.Model.Directory(); |
|
13 |
this.config = config; |
|
14 |
this.loadLibs(); |
|
15 |
} |
|
16 |
||
17 |
IriSP.Metadataplayer.prototype.toString = function() { |
|
18 |
return 'A Metadataplayer in DIV #' + this.config.gui.container; |
|
19 |
} |
|
20 |
||
21 |
IriSP.Metadataplayer.prototype.loadLibs = function() { |
|
22 |
console.log("Loading Libs"); |
|
23 |
// Localize jQuery variable |
|
24 |
IriSP.jQuery = null; |
|
25 |
var $L = $LAB.script(IriSP.getLib("jQuery")).script(IriSP.getLib("swfObject")).wait().script(IriSP.getLib("jQueryUI")); |
|
26 |
||
27 |
if(this.config.player.type === "jwplayer" || this.config.player.type === "allocine" || this.config.player.type === "dailymotion") { |
|
28 |
// load our popcorn.js lookalike |
|
29 |
$L.script(IriSP.getLib("jwplayer")); |
|
30 |
} else { |
|
31 |
// load the real popcorn |
|
32 |
$L.script(IriSP.getLib("popcorn")).script(IriSP.getLib("popcorn.code")); |
|
33 |
// load plugins if necessary |
|
34 |
if(this.config.player.type === "youtube") { |
|
35 |
$L.script(IriSP.getLib("popcorn.youtube")); |
|
36 |
} |
|
37 |
if(this.config.player.type === "vimeo"){ |
|
38 |
$L.script(IriSP.getLib("popcorn.vimeo")); |
|
39 |
} |
|
40 |
} |
|
41 |
||
42 |
/* widget specific requirements */ |
|
43 |
for(var _i = 0; _i < this.config.gui.widgets.length; _i++) { |
|
44 |
if(this.config.gui.widgets[_i].type === "PolemicWidget" || this.config.gui.widgets[_i].type === "StackGraphWidget" || this.config.gui.widgets[_i].type === "SparklineWidget") { |
|
45 |
$L.script(IriSP.getLib("raphael")); |
|
46 |
} |
|
47 |
if(this.config.gui.widgets[_i].type === "TraceWidget") { |
|
48 |
$L.script(IriSP.getLib("tracemanager")) |
|
49 |
} |
|
50 |
} |
|
51 |
|
|
52 |
var _this = this; |
|
53 |
|
|
54 |
$L.wait(function() { |
|
55 |
console.log("jQuery is loaded"); |
|
56 |
IriSP.jQuery = window.jQuery.noConflict(true); |
|
57 |
||
58 |
var css_link_jquery = IriSP.jQuery("<link>", { |
|
59 |
rel : "stylesheet", |
|
60 |
type : "text/css", |
|
61 |
href : IriSP.getLib("cssjQueryUI") |
|
62 |
}); |
|
63 |
var css_link_custom = IriSP.jQuery("<link>", { |
|
64 |
rel : "stylesheet", |
|
65 |
type : "text/css", |
|
66 |
href : _this.config.gui.css |
|
67 |
}); |
|
68 |
console.log('Appending CSS'); |
|
| 866 | 69 |
|
| 868 | 70 |
css_link_jquery.appendTo('head'); |
71 |
css_link_custom.appendTo('head'); |
|
72 |
|
|
73 |
console.log(_this); |
|
74 |
_this.onLibsLoaded(); |
|
75 |
|
|
76 |
}); |
|
77 |
} |
|
78 |
||
79 |
IriSP.Metadataplayer.prototype.loadMetadata = function(_metadataInfo) { |
|
80 |
if (typeof _metadataInfo.serializer === "undefined" && typeof _metadataInfo.format !== "undefined") { |
|
81 |
_metadataInfo.serializer = IriSP.serializers[_metadataInfo.format]; |
|
82 |
} |
|
83 |
if (typeof _metadataInfo.url === "undefined" && typeof _metadataInfo.src !== "undefined") { |
|
84 |
_metadataInfo.url = _metadataInfo.src; |
|
85 |
} |
|
86 |
console.log(_metadataInfo); |
|
87 |
if (typeof _metadataInfo.url !== "undefined" && typeof _metadataInfo.serializer !== "undefined") { |
|
88 |
return this.sourceManager.remoteSource(_metadataInfo); |
|
89 |
} else { |
|
90 |
return this.sourceManager.newLocalSource(_metadataInfo); |
|
91 |
} |
|
92 |
} |
|
93 |
||
94 |
IriSP.Metadataplayer.prototype.onLibsLoaded = function() { |
|
95 |
console.log("Libs Loaded"); |
|
96 |
this.videoData = this.loadMetadata(this.video_metadata); |
|
97 |
console.log(this.videoData); |
|
98 |
this.$ = IriSP.jQuery('#' + this.config.gui.container); |
|
99 |
this.$.css({ |
|
100 |
"width": this.config.gui.width, |
|
101 |
"clear": "both" |
|
102 |
}); |
|
103 |
if (typeof this.config.gui.height !== "undefined") { |
|
104 |
this.$.css("height", this.config.gui.height); |
|
105 |
} |
|
106 |
|
|
107 |
var _this = this; |
|
108 |
console.log("calling OnLoad"); |
|
109 |
this.videoData.onLoad(function() { |
|
110 |
_this.onVideoDataLoaded(); |
|
111 |
}); |
|
112 |
} |
|
113 |
||
114 |
IriSP.Metadataplayer.prototype.onVideoDataLoaded = function() { |
|
115 |
console.log("Video Data Loaded"); |
|
116 |
if (typeof this.videoData !== "undefined" && typeof this.config.player.video === "undefined") { |
|
117 |
var _media = this.videoData.currentMedia; |
|
118 |
if (typeof _media !== "undefined") { |
|
119 |
config.player.video = _media.video; |
|
120 |
if (typeof _media.streamer !== "undefined") { |
|
121 |
config.player.streamer = _media.streamer; |
|
122 |
config.player.video = _media.video.replace(_media.streamer,''); |
|
123 |
} |
|
124 |
} |
|
125 |
|
|
126 |
} |
|
127 |
this.configurePopcorn(config.player); |
|
128 |
this.widgets = []; |
|
129 |
for(var i = 0; i < this.config.gui.widgets.length; i++) { |
|
130 |
this.widgets.push(new IriSP.Widgets[_config.type](this, this.config.gui.widgets[i])); |
|
131 |
}; |
|
132 |
this.$('.Ldt-loader').detach(); |
|
133 |
} |
|
134 |
||
135 |
IriSP.Metadataplayer.prototype.configurePopcorn = function() { |
|
136 |
var pop, |
|
137 |
ret = this.layoutDivs(), |
|
138 |
containerDiv = ret[0], |
|
139 |
spacerDiv = ret[1]; |
|
140 |
||
141 |
/* insert one pixel of margin between the video and the first widget, |
|
142 |
* using the spacer. |
|
| 866 | 143 |
*/ |
| 868 | 144 |
IriSP.jQuery("#" + spacerDiv).css("height", Math.max(1, this.config.gui.spacer_div_height) + "px"); |
| 866 | 145 |
|
| 127 | 146 |
switch(options.type) { |
| 866 | 147 |
/* |
148 |
todo : dynamically create the div/video tag which |
|
149 |
will contain the video. |
|
150 |
*/ |
|
151 |
case "html5": |
|
152 |
var tmpId = Popcorn.guid("video"); |
|
153 |
IriSP.jQuery("#" + containerDiv).append("<video src='" + options.video + "' id='" + tmpId + "'></video>"); |
|
|
402
6148fb647f46
html5 video can now set the height and width of the video.
hamidouk
parents:
315
diff
changeset
|
154 |
|
| 866 | 155 |
if(options.hasOwnProperty("width")) |
156 |
IriSP.jQuery("#" + containerDiv).css("width", options.width); |
|
|
453
8568e47379a2
added autoconfiguration of the media source for rtmp streams.
hamidouk
parents:
430
diff
changeset
|
157 |
|
| 866 | 158 |
if(options.hasOwnProperty("height")) |
159 |
IriSP.jQuery("#" + containerDiv).css("height", options.height); |
|
160 |
pop = Popcorn("#" + tmpId); |
|
161 |
break; |
|
|
453
8568e47379a2
added autoconfiguration of the media source for rtmp streams.
hamidouk
parents:
430
diff
changeset
|
162 |
|
| 866 | 163 |
case "jwplayer": |
164 |
var opts = IriSP.jQuery.extend({}, options); |
|
165 |
delete opts.container; |
|
166 |
delete opts.type; |
|
167 |
opts.file = opts.video; |
|
168 |
delete opts.video; |
|
|
453
8568e47379a2
added autoconfiguration of the media source for rtmp streams.
hamidouk
parents:
430
diff
changeset
|
169 |
|
| 866 | 170 |
if(!options.hasOwnProperty("flashplayer")) { |
171 |
opts.flashplayer = IriSP.jwplayer_swf_path; |
|
|
816
e97e22801146
use href or url indiscriminately to get the source of the rtmp.
hamidouk
parents:
811
diff
changeset
|
172 |
} |
| 866 | 173 |
|
174 |
if(!options.hasOwnProperty("controlbar.position")) { |
|
175 |
opts["controlbar.position"] = "none"; |
|
176 |
} |
|
177 |
pop = new IriSP.PopcornReplacement.jwplayer("#" + containerDiv, opts); |
|
178 |
break; |
|
|
456
7fcdb501effd
added a switch to choose different options if using rtmp or not.
hamidouk
parents:
453
diff
changeset
|
179 |
|
| 866 | 180 |
case "youtube": |
181 |
var opts = IriSP.jQuery.extend({}, options); |
|
182 |
delete opts.container; |
|
183 |
opts.controls = 0; |
|
184 |
opts.autostart = false; |
|
185 |
// Popcorn.youtube wants us to specify the size of the player in the style attribute of its container div. |
|
186 |
IriSP.jQuery("#" + containerDiv).css({ |
|
187 |
width : opts.width + "px", |
|
188 |
height : opts.height + "px" |
|
189 |
}) |
|
190 |
pop = Popcorn.youtube("#" + containerDiv, opts.video, opts); |
|
191 |
break; |
|
|
558
29a370694c53
delete type variable which seemed to sometimes (but not always) confuse the jwplayer,
hamidouk
parents:
557
diff
changeset
|
192 |
|
| 866 | 193 |
case "dailymotion": |
194 |
pop = new IriSP.PopcornReplacement.dailymotion("#" + containerDiv, options); |
|
195 |
break; |
|
196 |
||
197 |
case "allocine": |
|
198 |
/* pass the options as-is to the allocine player and let it handle everything */ |
|
199 |
pop = new IriSP.PopcornReplacement.allocine("#" + containerDiv, options); |
|
200 |
break; |
|
| 868 | 201 |
|
| 866 | 202 |
default: |
203 |
pop = undefined; |
|
| 123 | 204 |
}; |
| 866 | 205 |
|
| 868 | 206 |
this.popcorn = pop; |
207 |
} |
|
| 866 | 208 |
|
| 868 | 209 |
/** create a subdiv with an unique id, and a spacer div as well. |
210 |
@param widgetName the name of the widget. |
|
211 |
@return an array of the form [createdivId, spacerdivId]. |
|
212 |
*/ |
|
213 |
IriSP.Metadataplayer.prototype.layoutDivs = function(_name) { |
|
214 |
if (typeof(_name) === "undefined") { |
|
215 |
_name = ""; |
|
| 866 | 216 |
} |
| 868 | 217 |
var newDiv = IriSP.guid(this.container + "_widget_" + _name + "_"), |
218 |
spacerDiv = IriSP.guid("LdtPlayer_spacer_"), |
|
219 |
divTempl = "<div id='{{id}}' style='width: {{width}}px; position: relative; clear: both;'></div>", |
|
220 |
spacerTempl = "<div id='{{spacer_id}}' style='width: {{width}}px; position: relative; height: {{spacer_div_height}}px;'></div>", |
|
221 |
divHtml = Mustache.to_html( divTempl, |
|
222 |
{ |
|
223 |
id: newDiv, |
|
224 |
width: this.config.gui.width |
|
225 |
}), |
|
226 |
spacerHtml = Mustache.to_html( spacerTempl, |
|
227 |
{ |
|
228 |
spacer_id: spacerDiv, |
|
229 |
width: this.config.gui.width, |
|
230 |
spacer_div_height: this.config.gui.height |
|
231 |
}); |
|
232 |
|
|
233 |
this.$.append(divCode); |
|
234 |
this.$.append(spacerCode); |
|
|
743
69a9969daa41
better defaults - paths are now computed at run-time.
hamidouk
parents:
707
diff
changeset
|
235 |
|
| 868 | 236 |
return [newDiv, spacerDiv]; |
| 866 | 237 |
}; |