| author | hamidouk |
| Tue, 13 Dec 2011 17:31:39 +0100 | |
| branch | popcorn-port |
| changeset 453 | 8568e47379a2 |
| parent 430 | c0b529ae20d2 |
| child 456 | 7fcdb501effd |
| permissions | -rw-r--r-- |
| 123 | 1 |
/* init.js - initialization and configuration of Popcorn and the widgets |
2 |
exemple json configuration: |
|
|
141
becd5f52fa24
this commit fixes an elusive integration bug where the object would get called
hamidouk
parents:
136
diff
changeset
|
3 |
|
| 123 | 4 |
*/ |
5 |
||
|
453
8568e47379a2
added autoconfiguration of the media source for rtmp streams.
hamidouk
parents:
430
diff
changeset
|
6 |
IriSP.setupDataLoader = function() { |
|
8568e47379a2
added autoconfiguration of the media source for rtmp streams.
hamidouk
parents:
430
diff
changeset
|
7 |
/* we set it up separately because we need to |
|
8568e47379a2
added autoconfiguration of the media source for rtmp streams.
hamidouk
parents:
430
diff
changeset
|
8 |
get data at the very beginning, for instance when |
|
8568e47379a2
added autoconfiguration of the media source for rtmp streams.
hamidouk
parents:
430
diff
changeset
|
9 |
setting up the video */ |
|
8568e47379a2
added autoconfiguration of the media source for rtmp streams.
hamidouk
parents:
430
diff
changeset
|
10 |
IriSP.__dataloader = new IriSP.DataLoader(); |
|
8568e47379a2
added autoconfiguration of the media source for rtmp streams.
hamidouk
parents:
430
diff
changeset
|
11 |
}; |
|
8568e47379a2
added autoconfiguration of the media source for rtmp streams.
hamidouk
parents:
430
diff
changeset
|
12 |
|
|
158
1813e6e4f0d6
made a small change to the way popcorn is integrated into the page.
hamidouk
parents:
141
diff
changeset
|
13 |
IriSP.configurePopcorn = function (layoutManager, options) { |
| 123 | 14 |
var pop; |
|
287
5c7495102bd7
added a spacer div to simplify some graphic animations.
hamidouk
parents:
216
diff
changeset
|
15 |
var ret = layoutManager.createDiv(); |
|
5c7495102bd7
added a spacer div to simplify some graphic animations.
hamidouk
parents:
216
diff
changeset
|
16 |
var containerDiv = ret[0]; |
| 123 | 17 |
|
| 127 | 18 |
switch(options.type) { |
| 123 | 19 |
/* |
20 |
todo : dynamically create the div/video tag which |
|
21 |
will contain the video. |
|
22 |
*/ |
|
23 |
case "html5": |
|
|
158
1813e6e4f0d6
made a small change to the way popcorn is integrated into the page.
hamidouk
parents:
141
diff
changeset
|
24 |
var tmpId = Popcorn.guid("video"); |
|
1813e6e4f0d6
made a small change to the way popcorn is integrated into the page.
hamidouk
parents:
141
diff
changeset
|
25 |
IriSP.jQuery("#" + containerDiv).append("<video src='" + options.file + "' id='" + tmpId + "'></video>"); |
|
402
6148fb647f46
html5 video can now set the height and width of the video.
hamidouk
parents:
315
diff
changeset
|
26 |
|
|
6148fb647f46
html5 video can now set the height and width of the video.
hamidouk
parents:
315
diff
changeset
|
27 |
if (options.hasOwnProperty("width")) |
|
6148fb647f46
html5 video can now set the height and width of the video.
hamidouk
parents:
315
diff
changeset
|
28 |
IriSP.jQuery("#" + containerDiv).css("width", options.width); |
|
6148fb647f46
html5 video can now set the height and width of the video.
hamidouk
parents:
315
diff
changeset
|
29 |
|
|
6148fb647f46
html5 video can now set the height and width of the video.
hamidouk
parents:
315
diff
changeset
|
30 |
if (options.hasOwnProperty("height")) |
|
6148fb647f46
html5 video can now set the height and width of the video.
hamidouk
parents:
315
diff
changeset
|
31 |
IriSP.jQuery("#" + containerDiv).css("height", options.height); |
|
6148fb647f46
html5 video can now set the height and width of the video.
hamidouk
parents:
315
diff
changeset
|
32 |
|
| 216 | 33 |
pop = Popcorn("#" + tmpId).mediafragment({start : 0}); |
| 123 | 34 |
break; |
| 127 | 35 |
|
36 |
case "jwplayer": |
|
37 |
var opts = IriSP.jQuery.extend({}, options); |
|
38 |
delete opts.container; |
|
|
453
8568e47379a2
added autoconfiguration of the media source for rtmp streams.
hamidouk
parents:
430
diff
changeset
|
39 |
|
|
8568e47379a2
added autoconfiguration of the media source for rtmp streams.
hamidouk
parents:
430
diff
changeset
|
40 |
/* exit if we can't access the metadata */ |
|
8568e47379a2
added autoconfiguration of the media source for rtmp streams.
hamidouk
parents:
430
diff
changeset
|
41 |
if (typeof(IriSP.__jsonMetadata) === "undefined") { |
|
8568e47379a2
added autoconfiguration of the media source for rtmp streams.
hamidouk
parents:
430
diff
changeset
|
42 |
break; |
|
8568e47379a2
added autoconfiguration of the media source for rtmp streams.
hamidouk
parents:
430
diff
changeset
|
43 |
}; |
|
8568e47379a2
added autoconfiguration of the media source for rtmp streams.
hamidouk
parents:
430
diff
changeset
|
44 |
|
|
8568e47379a2
added autoconfiguration of the media source for rtmp streams.
hamidouk
parents:
430
diff
changeset
|
45 |
|
|
8568e47379a2
added autoconfiguration of the media source for rtmp streams.
hamidouk
parents:
430
diff
changeset
|
46 |
// the json format is totally illogical |
|
8568e47379a2
added autoconfiguration of the media source for rtmp streams.
hamidouk
parents:
430
diff
changeset
|
47 |
opts.streamer = IriSP.__jsonMetadata["medias"][0]["meta"]["item"]["value"]; |
|
8568e47379a2
added autoconfiguration of the media source for rtmp streams.
hamidouk
parents:
430
diff
changeset
|
48 |
var source = IriSP.__jsonMetadata["medias"][0]["href"]; |
|
8568e47379a2
added autoconfiguration of the media source for rtmp streams.
hamidouk
parents:
430
diff
changeset
|
49 |
|
|
8568e47379a2
added autoconfiguration of the media source for rtmp streams.
hamidouk
parents:
430
diff
changeset
|
50 |
// the source if a full url but jwplayer wants an url relative to the |
|
8568e47379a2
added autoconfiguration of the media source for rtmp streams.
hamidouk
parents:
430
diff
changeset
|
51 |
// streamer url, so we've got to remove the common part. |
|
8568e47379a2
added autoconfiguration of the media source for rtmp streams.
hamidouk
parents:
430
diff
changeset
|
52 |
opts.file = source.slice(opts.streamer.length); |
|
430
c0b529ae20d2
don't overwrite popcorn when using our jwplayer wrapper.
hamidouk
parents:
422
diff
changeset
|
53 |
pop = IriSP.PopcornReplacement.jwplayer("#" + containerDiv, opts); |
| 127 | 54 |
break; |
| 198 | 55 |
|
56 |
case "youtube": |
|
57 |
var opts = IriSP.jQuery.extend({}, options); |
|
58 |
delete opts.container; |
|
59 |
opts.controls = 0; |
|
60 |
opts.autostart = false; |
|
| 204 | 61 |
templ = "width: {{width}}px; height: {{height}}px;"; |
| 198 | 62 |
var str = Mustache.to_html(templ, {width: opts.width, height: opts.height}); |
63 |
// Popcorn.youtube wants us to specify the size of the player in the style attribute of its container div. |
|
64 |
IriSP.jQuery("#" + containerDiv).attr("style", str); |
|
65 |
|
|
| 216 | 66 |
pop = Popcorn.youtube("#" + containerDiv, opts.video, opts).mediafragment({start : 0}); |
| 198 | 67 |
break; |
| 127 | 68 |
|
69 |
default: |
|
70 |
pop = undefined; |
|
| 123 | 71 |
}; |
72 |
|
|
| 127 | 73 |
return pop; |
| 123 | 74 |
}; |
75 |
||
|
158
1813e6e4f0d6
made a small change to the way popcorn is integrated into the page.
hamidouk
parents:
141
diff
changeset
|
76 |
IriSP.configureWidgets = function (popcornInstance, layoutManager, guiOptions) { |
|
453
8568e47379a2
added autoconfiguration of the media source for rtmp streams.
hamidouk
parents:
430
diff
changeset
|
77 |
|
|
8568e47379a2
added autoconfiguration of the media source for rtmp streams.
hamidouk
parents:
430
diff
changeset
|
78 |
var serialFactory = new IriSP.SerializerFactory(IriSP.__dataloader); |
| 127 | 79 |
var params = {width: guiOptions.width, height: guiOptions.height}; |
|
158
1813e6e4f0d6
made a small change to the way popcorn is integrated into the page.
hamidouk
parents:
141
diff
changeset
|
80 |
|
| 127 | 81 |
var ret_widgets = []; |
|
141
becd5f52fa24
this commit fixes an elusive integration bug where the object would get called
hamidouk
parents:
136
diff
changeset
|
82 |
var index; |
| 127 | 83 |
|
|
141
becd5f52fa24
this commit fixes an elusive integration bug where the object would get called
hamidouk
parents:
136
diff
changeset
|
84 |
for (index = 0; index < guiOptions.widgets.length; index++) { |
|
171
158f0193ec54
added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents:
158
diff
changeset
|
85 |
var widgetConfig = guiOptions.widgets[index]; |
|
158f0193ec54
added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents:
158
diff
changeset
|
86 |
var widget = IriSP.instantiateWidget(popcornInstance, serialFactory, layoutManager, widgetConfig); |
| 127 | 87 |
ret_widgets.push(widget); |
|
141
becd5f52fa24
this commit fixes an elusive integration bug where the object would get called
hamidouk
parents:
136
diff
changeset
|
88 |
|
| 127 | 89 |
}; |
|
141
becd5f52fa24
this commit fixes an elusive integration bug where the object would get called
hamidouk
parents:
136
diff
changeset
|
90 |
|
| 127 | 91 |
return ret_widgets; |
|
171
158f0193ec54
added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents:
158
diff
changeset
|
92 |
}; |
|
158f0193ec54
added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents:
158
diff
changeset
|
93 |
|
|
158f0193ec54
added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents:
158
diff
changeset
|
94 |
IriSP.instantiateWidget = function(popcornInstance, serialFactory, layoutManager, widgetConfig) { |
|
287
5c7495102bd7
added a spacer div to simplify some graphic animations.
hamidouk
parents:
216
diff
changeset
|
95 |
/* create div returns us a container for the widget and a spacer */ |
|
315
4466bf448426
updated layout and init to give more meaningful names to the widgets divs.
hamidouk
parents:
287
diff
changeset
|
96 |
var ret = layoutManager.createDiv(widgetConfig.type); |
|
287
5c7495102bd7
added a spacer div to simplify some graphic animations.
hamidouk
parents:
216
diff
changeset
|
97 |
var container = ret[0]; |
|
5c7495102bd7
added a spacer div to simplify some graphic animations.
hamidouk
parents:
216
diff
changeset
|
98 |
var spacer = ret[1]; |
|
5c7495102bd7
added a spacer div to simplify some graphic animations.
hamidouk
parents:
216
diff
changeset
|
99 |
|
| 175 | 100 |
var arr = IriSP.jQuery.extend({}, widgetConfig); |
|
171
158f0193ec54
added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents:
158
diff
changeset
|
101 |
arr.container = container; |
|
287
5c7495102bd7
added a spacer div to simplify some graphic animations.
hamidouk
parents:
216
diff
changeset
|
102 |
arr.spacer = spacer; |
| 175 | 103 |
|
|
171
158f0193ec54
added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents:
158
diff
changeset
|
104 |
var serializer = serialFactory.getSerializer(widgetConfig.metadata); |
| 175 | 105 |
|
106 |
if (typeof serializer == "undefined") |
|
107 |
debugger; |
|
108 |
|
|
|
171
158f0193ec54
added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents:
158
diff
changeset
|
109 |
// instantiate the object passed as a string |
|
158f0193ec54
added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents:
158
diff
changeset
|
110 |
var widget = new IriSP[widgetConfig.type](popcornInstance, arr, serializer); |
|
158f0193ec54
added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents:
158
diff
changeset
|
111 |
|
|
158f0193ec54
added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents:
158
diff
changeset
|
112 |
if (widgetConfig.hasOwnProperty("requires")) { |
|
158f0193ec54
added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents:
158
diff
changeset
|
113 |
// also create the widgets this one depends on. |
|
158f0193ec54
added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents:
158
diff
changeset
|
114 |
// the dependency widget is available in the parent widget context as |
|
158f0193ec54
added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents:
158
diff
changeset
|
115 |
// this.WidgetName (for instance, this.TipWidget); |
|
158f0193ec54
added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents:
158
diff
changeset
|
116 |
|
| 175 | 117 |
var i = 0; |
118 |
for(i = 0; i < widgetConfig.requires.length; i++) { |
|
119 |
var widgetName = widgetConfig.requires[i]["type"]; |
|
120 |
widget[widgetName] = IriSP.instantiateWidget(popcornInstance, serialFactory, layoutManager, widgetConfig.requires[i]); |
|
|
171
158f0193ec54
added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents:
158
diff
changeset
|
121 |
} |
| 175 | 122 |
} |
123 |
|
|
|
171
158f0193ec54
added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents:
158
diff
changeset
|
124 |
serializer.sync(IriSP.wrap(widget, function() { this.draw(); })); |
|
158f0193ec54
added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents:
158
diff
changeset
|
125 |
return widget; |
|
287
5c7495102bd7
added a spacer div to simplify some graphic animations.
hamidouk
parents:
216
diff
changeset
|
126 |
}; |