|
959
|
1 |
IriSP.Widgets.MashupPlayer = function(player, config) { |
|
|
2 |
IriSP.Widgets.Widget.call(this, player, config); |
|
|
3 |
this.is_mashup = true; |
|
|
4 |
}; |
|
|
5 |
|
|
|
6 |
IriSP.Widgets.MashupPlayer.prototype = new IriSP.Widgets.Widget(); |
|
|
7 |
|
|
|
8 |
/* A Popcorn-based player for HTML5 Video, Youtube and Vimeo */ |
|
|
9 |
|
|
|
10 |
IriSP.Widgets.MashupPlayer.prototype.defaults = { |
|
|
11 |
aspect_ratio: 14/9, |
|
965
|
12 |
split_screen: false, |
|
967
|
13 |
player_type: "PopcornPlayer", |
|
|
14 |
background: "#000000" |
|
959
|
15 |
} |
|
|
16 |
|
|
|
17 |
IriSP.Widgets.MashupPlayer.prototype.draw = function() { |
|
|
18 |
var _this = this, |
|
|
19 |
_mashup = this.media, |
|
967
|
20 |
_pauseState = (!this.autostart && !this.autoplay), |
|
959
|
21 |
_currentMedia = null, |
|
|
22 |
_currentAnnotation = null, |
|
|
23 |
_segmentBegin, |
|
|
24 |
_segmentEnd, |
|
|
25 |
_timecode = 0, |
|
|
26 |
_timedelta; |
|
|
27 |
|
|
|
28 |
function changeCurrentAnnotation() { |
|
|
29 |
var _annotation = _mashup.getAnnotationAtTime( _timecode ); |
|
|
30 |
if (typeof _annotation === "undefined") { |
|
|
31 |
if (_currentMedia) { |
|
|
32 |
_currentMedia.pause(); |
|
|
33 |
if (!_pauseState) { |
|
|
34 |
_pauseState = true; |
|
|
35 |
_mashup.trigger("pause"); |
|
|
36 |
} |
|
|
37 |
} |
|
|
38 |
return; |
|
|
39 |
} |
|
|
40 |
if (_annotation !== _currentAnnotation) { |
|
|
41 |
_currentAnnotation = _annotation; |
|
|
42 |
_segmentBegin = _currentAnnotation.annotation.begin.milliseconds; |
|
|
43 |
_segmentEnd = _currentAnnotation.annotation.end.milliseconds; |
|
|
44 |
_timedelta = _segmentBegin - _currentAnnotation.begin.milliseconds; |
|
|
45 |
_currentMedia = _currentAnnotation.getMedia(); |
|
|
46 |
|
|
|
47 |
for (var _i = 0; _i < _mashup.medias.length; _i++) { |
|
|
48 |
if (_mashup.medias[_i].id !== _currentMedia.id) { |
|
965
|
49 |
if (!_this.split_screen) { |
|
|
50 |
_mashup.medias[_i].hide(); |
|
|
51 |
} |
|
959
|
52 |
_mashup.medias[_i].pause(); |
|
|
53 |
} else { |
|
|
54 |
_mashup.medias[_i].show(); |
|
|
55 |
} |
|
|
56 |
} |
|
|
57 |
|
|
|
58 |
/* PRELOADING */ |
|
|
59 |
var _preloadedMedias = [], |
|
|
60 |
_toPreload = _mashup.getAnnotations().filter(function(_a) { |
|
|
61 |
return (_a.begin >= _currentAnnotation.end && _a.getMedia() !== _currentMedia); |
|
|
62 |
}); |
|
|
63 |
IriSP._(_toPreload).each(function(_a) { |
|
|
64 |
var _media = _a.getMedia(); |
|
|
65 |
if (IriSP._(_preloadedMedias).indexOf(_media.id) === -1) { |
|
|
66 |
_preloadedMedias.push(_media.id); |
|
|
67 |
_media.setCurrentTime(_a.annotation.begin.getSeconds()); |
|
|
68 |
//console.log("Preloading ", _media.id, " at t=", _a.annotation.begin.getSeconds()); |
|
|
69 |
} |
|
|
70 |
}); |
|
|
71 |
|
|
|
72 |
// console.log("Changed segment: media="+ this.currentMedia.id + ", from=" + this.segmentBegin + " to=" + this.segmentEnd +", timedelta = ", this.timedelta) |
|
|
73 |
// } else { |
|
|
74 |
// console.log("changeCurrentAnnotation called, but segment hasn't changed"); |
|
|
75 |
} |
|
|
76 |
|
|
965
|
77 |
if (!_pauseState) { |
|
|
78 |
_currentMedia.play(); |
|
|
79 |
} |
|
959
|
80 |
_currentMedia.setCurrentTime( _timecode + _timedelta); |
|
|
81 |
_mashup.trigger("timeupdate", new IriSP.Model.Time(_timecode)); |
|
|
82 |
|
|
|
83 |
} |
|
|
84 |
|
|
|
85 |
if (!this.height) { |
|
|
86 |
this.height = Math.floor(this.width/this.aspect_ratio); |
|
|
87 |
this.$.css({ |
|
|
88 |
height: this.height |
|
|
89 |
}); |
|
|
90 |
} |
|
965
|
91 |
|
|
967
|
92 |
this.$.css({ |
|
|
93 |
background: this.background |
|
|
94 |
}); |
|
|
95 |
|
|
965
|
96 |
var _grid = Math.ceil(Math.sqrt(_mashup.medias.length)), |
|
|
97 |
_width = (this.split_screen ? this.width / _grid : this.width), |
|
|
98 |
_height = (this.split_screen ? this.height / _grid : this.height) |
|
959
|
99 |
|
|
965
|
100 |
IriSP._(_mashup.medias).each(function(_media, _key) { |
|
|
101 |
var _el = IriSP.jQuery('<div class="Ldt-MashupPlayer-Media"><div class="Ldt-MashupPlayer-Subwidget"></div></div>'); |
|
959
|
102 |
_el.css({ |
|
|
103 |
position: "absolute", |
|
965
|
104 |
top: (_this.split_screen ? _height * Math.floor(_key / _grid) : 0), |
|
|
105 |
left: (_this.split_screen ? _width * (_key % _grid) : 0), |
|
|
106 |
height: _height, |
|
|
107 |
width: _width, |
|
|
108 |
display: (_this.split_screen ? "block" : "none") |
|
959
|
109 |
}); |
|
|
110 |
_this.$.append(_el); |
|
|
111 |
|
|
|
112 |
_this.insertSubwidget( |
|
965
|
113 |
_el.find(".Ldt-MashupPlayer-Subwidget"), |
|
|
114 |
IriSP._({ |
|
959
|
115 |
type: _this.player_type, |
|
|
116 |
media_id: _media.id, |
|
965
|
117 |
height: _height, |
|
|
118 |
width: _width, |
|
959
|
119 |
url_transform: _this.url_transform |
|
965
|
120 |
}).extend(_this.player_options) |
|
959
|
121 |
); |
|
|
122 |
|
|
|
123 |
_media.loadedMetadata = false; |
|
|
124 |
_media.show = function() { |
|
|
125 |
_el.show(); |
|
|
126 |
}; |
|
|
127 |
_media.hide = function() { |
|
|
128 |
_el.hide(); |
|
|
129 |
}; |
|
|
130 |
_media.on("loadedmetadata", function() { |
|
|
131 |
_media.loadedMetadata = true; |
|
|
132 |
var _allLoaded = true; |
|
|
133 |
for (var _i = 0; _i < _mashup.medias.length; _i++) { |
|
|
134 |
_allLoaded = _allLoaded && _mashup.medias[_i].loadedMetadata; |
|
|
135 |
} |
|
|
136 |
if (_allLoaded) { |
|
|
137 |
changeCurrentAnnotation(); |
|
|
138 |
_mashup.trigger("loadedmetadata"); |
|
|
139 |
} |
|
|
140 |
}); |
|
|
141 |
_media.on("timeupdate", function(_time) { |
|
|
142 |
if (!_pauseState && _media === _currentMedia) { |
|
|
143 |
// var _status = "Timeupdate from " + _media.id + " at time " + _time; |
|
|
144 |
if ( _time < _segmentEnd ) { |
|
|
145 |
if ( _time >= _segmentBegin ) { |
|
|
146 |
_timecode = _time - _timedelta; |
|
|
147 |
// _status += " within segment"; |
|
|
148 |
} else { |
|
|
149 |
_timecode = _segmentBegin - _timedelta; |
|
|
150 |
_media.setCurrentTime(_segmentBegin); |
|
|
151 |
// _status += " before segment"; |
|
|
152 |
} |
|
|
153 |
} else { |
|
|
154 |
_timecode = _segmentEnd - _timedelta; |
|
|
155 |
_media.pause(); |
|
|
156 |
changeCurrentAnnotation(); |
|
|
157 |
// _status += " after segment"; |
|
|
158 |
} |
|
|
159 |
// _status += " (" + _this.segmentBegin + " to " + _this.segmentEnd + ")" + ", translated to " + _this.timecode; |
|
|
160 |
// console.log(_status); |
|
|
161 |
_mashup.trigger("timeupdate", new IriSP.Model.Time(_timecode)); |
|
|
162 |
} |
|
|
163 |
}); |
|
|
164 |
_media.on("play", function() { |
|
|
165 |
if (_media === _currentMedia) { |
|
|
166 |
_mashup.trigger("play"); |
|
|
167 |
} |
|
|
168 |
}); |
|
|
169 |
_media.on("pause", function() { |
|
|
170 |
if (_media === _currentMedia) { |
|
|
171 |
_mashup.trigger("pause"); |
|
|
172 |
} |
|
|
173 |
}); |
|
|
174 |
}); |
|
|
175 |
|
|
|
176 |
_mashup.getCurrentTime = function() { |
|
|
177 |
return new IriSP.Model.Time(_timecode); |
|
|
178 |
} |
|
|
179 |
_mashup.getVolume = function() { |
|
|
180 |
return ( _currentMedia ? _currentMedia.getVolume() : .5 ); |
|
|
181 |
} |
|
|
182 |
_mashup.getPaused = function() { |
|
|
183 |
return _pauseState; |
|
|
184 |
} |
|
|
185 |
_mashup.getMuted = function() { |
|
|
186 |
return ( _currentMedia ? _currentMedia.getMuted() : false ); |
|
|
187 |
} |
|
|
188 |
_mashup.setCurrentTime = function(_milliseconds) { |
|
|
189 |
_timecode = _milliseconds; |
|
|
190 |
changeCurrentAnnotation(); |
|
|
191 |
} |
|
|
192 |
_mashup.setVolume = function(_vol) { |
|
|
193 |
for (var _i = 0; _i < _mashup.medias.length; _i++) { |
|
|
194 |
_mashup.medias[_i].setVolume(_vol); |
|
|
195 |
} |
|
|
196 |
} |
|
|
197 |
_mashup.mute = function() { |
|
|
198 |
for (var _i = 0; _i < _mashup.medias.length; _i++) { |
|
|
199 |
_mashup.medias[_i].mute(); |
|
|
200 |
} |
|
|
201 |
} |
|
|
202 |
_mashup.unmute = function() { |
|
|
203 |
for (var _i = 0; _i < _mashup.medias.length; _i++) { |
|
|
204 |
_mashup.medias[_i].unmute(); |
|
|
205 |
} |
|
|
206 |
} |
|
|
207 |
_mashup.play = function() { |
|
|
208 |
_pauseState = false; |
|
|
209 |
changeCurrentAnnotation(); |
|
|
210 |
} |
|
|
211 |
_mashup.pause = function() { |
|
|
212 |
_pauseState = true; |
|
|
213 |
if (_currentMedia) { |
|
|
214 |
_currentMedia.pause(); |
|
|
215 |
} |
|
|
216 |
} |
|
|
217 |
|
|
967
|
218 |
_mashup.on("loadedmetadata", changeCurrentAnnotation); |
|
959
|
219 |
|
|
|
220 |
} |