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