|
27
|
1 |
IriSP.Hashcut = function(options) { |
|
22
|
2 |
|
|
|
3 |
/* Load Media List */ |
|
|
4 |
|
|
|
5 |
var directory = new IriSP.Model.Directory(), |
|
|
6 |
project = directory.remoteSource({ |
|
27
|
7 |
url: options.url, |
|
22
|
8 |
serializer: IriSP.serializers.medialist |
|
|
9 |
}), |
|
25
|
10 |
mashup = new IriSP.Model.Mashup(false, project), |
|
27
|
11 |
mediatemplate = _.template('<li class="item-video" data-media-id="<%= id %>"><img src="<%= thumbnail %>" alt="<%= title %>" />' |
|
|
12 |
+ '<span class="video-info"><span class="title-video"><%= title %></span><span class="author"><%= description %></span>' |
|
|
13 |
+ '<span class="time-length">Durée : <span><%= duration.toString() %></span></span></span></li>'), |
|
|
14 |
segmenttemplate = _.template('<li class="item-video" data-segment-id="<%= annotation.id %>" data-media-id="<%= annotation.getMedia().id %>">' |
|
|
15 |
+ '<img src="<%= annotation.getMedia().thumbnail %>" alt="<%= annotation.getMedia().title %>" />' |
|
|
16 |
+ '<span class="video-info"><span class="title-video"><%= annotation.getMedia().title %></span>' |
|
|
17 |
+ '<span class="subtitle"><%= annotation.title %></span><span class="duration"><%= annotation.begin.toString() %> - <%= annotation.end.toString() %> (<%= annotation.getDuration().toString() %>)</span>' |
|
|
18 |
+ '<ul class="tools"><li><a class="edit" href="#" title="Éditer le segment"></a></li><li><a class="bottom" href="#" title="Descendre le segment"></a></li>' |
|
|
19 |
+ '<li><a class="top" href="#" title="Remonter le segment"></a></li><li><a class="delete" href="#" title="Supprimer le segment"></a></li></ul></span></li>'), |
|
|
20 |
viztemplate = _.template('<div class="frise-segment" style="background-color:<%= color %>; left:<%= left %>%; width:<%= width %>%;"></div>'), |
|
|
21 |
intervaltemplate = _.template('<span class="frise-indication" style="left:<%= left %>%;"><%= time.toString() %></span>'); |
|
22
|
22 |
|
|
|
23 |
/* Fill left column with Media List */ |
|
25
|
24 |
|
|
22
|
25 |
project.onLoad(function() { |
|
|
26 |
var html = ''; |
|
|
27 |
project.getMedias().forEach(function(_m) { |
|
27
|
28 |
html += mediatemplate(_m); |
|
13
|
29 |
}); |
|
22
|
30 |
$(".col-left .list-video").html(html); |
|
|
31 |
}); |
|
|
32 |
|
|
|
33 |
/* Search Media with left column form */ |
|
|
34 |
|
|
|
35 |
$(".col-left input").on("keyup change input paste", function() { |
|
|
36 |
var val = $(this).val(); |
|
|
37 |
if (val) { |
|
|
38 |
var find = IriSP.Model.regexpFromTextOrArray(val, true), |
|
|
39 |
replace = IriSP.Model.regexpFromTextOrArray(val, false); |
|
|
40 |
} |
|
|
41 |
$(".col-left .item-video").each(function() { |
|
|
42 |
var li = $(this), |
|
|
43 |
title = $(this).find(".title-video"), |
|
|
44 |
titletext = title.text(); |
|
|
45 |
if (val && find.test(titletext)) { |
|
|
46 |
title.html(titletext.replace(replace, '<span style="background: yellow;">$1</span>')); |
|
|
47 |
li.show(); |
|
|
48 |
} else { |
|
|
49 |
title.text(titletext); |
|
|
50 |
if (val) { |
|
|
51 |
li.hide(); |
|
13
|
52 |
} else { |
|
22
|
53 |
li.show(); |
|
13
|
54 |
} |
|
22
|
55 |
} |
|
|
56 |
}) |
|
|
57 |
}); |
|
|
58 |
|
|
25
|
59 |
/* Fill right column when mashup is updated */ |
|
|
60 |
|
|
27
|
61 |
function setPointerToCurrentAnnotation() { |
|
|
62 |
if (mashupCurrentAnnotation) { |
|
|
63 |
var p = (mashupCurrentAnnotation.begin + mashupCurrentAnnotation.end) / (2 * mashup.duration); |
|
|
64 |
$(".mashup-description .pointer").css("left", (100 * p) + "%"); |
|
|
65 |
} |
|
25
|
66 |
} |
|
|
67 |
|
|
27
|
68 |
function updateMashupUI() { |
|
|
69 |
var listhtml = '', vizhtml = '', t = 0, k = mashup.duration ? (100 / mashup.duration) : 0; |
|
|
70 |
mashup.segments.forEach(function(_s) { |
|
|
71 |
listhtml += segmenttemplate(_s); |
|
|
72 |
var vizdata = { |
|
|
73 |
left: k * t, |
|
|
74 |
width: k * _s.duration, |
|
|
75 |
color: _s.getMedia().color |
|
|
76 |
} |
|
|
77 |
vizhtml += viztemplate(vizdata); |
|
|
78 |
t += _s.duration.milliseconds; |
|
|
79 |
}); |
|
|
80 |
|
|
|
81 |
var intervals = [ 1000, 2000, 5000, 10000, 30000, 60000, 120000, 300000, 600000, 900000, 1800000, 3600000, 7200000 ]; |
|
|
82 |
|
|
|
83 |
function createIntervals(maxn) { |
|
|
84 |
for (var i = 0; i < intervals.length; i++) { |
|
|
85 |
if (mashup.duration / intervals[i] <= maxn) { |
|
|
86 |
var html = ''; |
|
|
87 |
for (var j = intervals[i]; j < mashup.duration; j += intervals[i]) { |
|
|
88 |
html += intervaltemplate({ left: k * j, time: new IriSP.Model.Time(j) }); |
|
|
89 |
} |
|
|
90 |
return html; |
|
|
91 |
} |
|
|
92 |
} |
|
|
93 |
return ""; |
|
|
94 |
} |
|
|
95 |
|
|
|
96 |
$(".col-right .list-video").html(listhtml).find(".item-video:last-child .bottom, .item-video:first-child .top").addClass("disable"); |
|
|
97 |
$(".mashup-total-duration").text(mashup.duration.toString()); |
|
|
98 |
$(".frise-segments").html(vizhtml); |
|
|
99 |
$(".col-right .frise-indications").html(createIntervals(4)); |
|
|
100 |
$(".bloc-pvw .frise-indications").html(createIntervals(8)); |
|
|
101 |
highlightCurrentSegment(); |
|
|
102 |
if (currentMedia === mashup) { |
|
|
103 |
$(".Ldt-Ctrl-Time-Total").text(currentMedia.duration.toString()); |
|
|
104 |
if (mashupTimecode > mashup.duration) { |
|
|
105 |
mashup.setCurrentTime(mashup.duration); |
|
|
106 |
} |
|
|
107 |
changeCurrentAnnotation(); |
|
|
108 |
setPointerToCurrentAnnotation(); |
|
|
109 |
} |
|
|
110 |
} |
|
|
111 |
|
|
|
112 |
mashup.on("change",updateMashupUI); |
|
25
|
113 |
|
|
22
|
114 |
/* Slider */ |
|
|
115 |
|
|
23
|
116 |
var timeSlider = $(".Ldt-Slider"), |
|
|
117 |
slidersRange = 920; |
|
22
|
118 |
timeSlider.slider({ |
|
|
119 |
range: "min", |
|
|
120 |
value: 0, |
|
|
121 |
min: 0, |
|
23
|
122 |
max: slidersRange, |
|
22
|
123 |
slide: function(event, ui) { |
|
23
|
124 |
if (currentMedia) { |
|
|
125 |
var t = currentMedia.duration * ui.value / slidersRange; |
|
|
126 |
currentMedia.setCurrentTime(t); |
|
|
127 |
} |
|
22
|
128 |
} |
|
|
129 |
}); |
|
|
130 |
|
|
|
131 |
var timeSliderHandle = timeSlider.find('.ui-slider-handle'), |
|
|
132 |
timeSliderMaximized = false, |
|
|
133 |
timeSliderTimeoutId = false, |
|
|
134 |
timeSliderMinimizedHeight = 4, |
|
|
135 |
timeSliderMaximizedHeight = 10, |
|
|
136 |
timeSliderTimeoutDuration = 1500, |
|
|
137 |
timeTooltip = $(".Ldt-Slider-Time"); |
|
|
138 |
|
|
|
139 |
timeSlider.css(calculateSliderCss(timeSliderMinimizedHeight)); |
|
|
140 |
timeSliderHandle.css(calculateHandleCss(timeSliderMinimizedHeight)); |
|
|
141 |
|
|
|
142 |
function timeSliderMouseOver() { |
|
|
143 |
if (timeSliderTimeoutId) { |
|
|
144 |
window.clearTimeout(timeSliderTimeoutId); |
|
|
145 |
timeSliderTimeoutId = false; |
|
|
146 |
} |
|
|
147 |
if (!timeSliderMaximized) { |
|
|
148 |
timeSliderAnimateToHeight(timeSliderMaximizedHeight); |
|
|
149 |
timeSliderMaximized = true; |
|
|
150 |
} |
|
|
151 |
} |
|
|
152 |
|
|
|
153 |
function timeSliderMouseOut() { |
|
|
154 |
timeTooltip.hide(); |
|
|
155 |
if (timeSliderTimeoutId) { |
|
|
156 |
clearTimeout(timeSliderTimeoutId); |
|
|
157 |
timeSliderTimeoutId = false; |
|
|
158 |
} |
|
|
159 |
timeSliderTimeoutId = setTimeout(function() { |
|
|
160 |
if (timeSliderMaximized) { |
|
|
161 |
timeSliderAnimateToHeight(timeSliderMinimizedHeight); |
|
|
162 |
timeSliderMaximized = false; |
|
|
163 |
} |
|
|
164 |
timeSliderTimeoutId = false; |
|
|
165 |
}, timeSliderTimeoutDuration); |
|
|
166 |
} |
|
|
167 |
|
|
|
168 |
timeSlider |
|
|
169 |
.mouseover(function() { |
|
|
170 |
timeTooltip.show(); |
|
|
171 |
timeSliderMouseOver(); |
|
|
172 |
}) |
|
|
173 |
.mouseout(timeSliderMouseOut) |
|
|
174 |
.mousemove(function(_e) { |
|
|
175 |
var _x = _e.pageX - timeSlider.offset().left, |
|
23
|
176 |
_t = new IriSP.Model.Time( |
|
|
177 |
currentMedia ? currentMedia.duration * _x / timeSlider.width() : 0 |
|
|
178 |
); |
|
22
|
179 |
timeTooltip.text(_t.toString()).css("left",_x); |
|
15
|
180 |
}); |
|
22
|
181 |
|
|
|
182 |
$(".Ldt-Ctrl").mouseover(timeSliderMouseOver).mouseout(timeSliderMouseOut); |
|
|
183 |
|
|
|
184 |
function timeSliderAnimateToHeight(_height) { |
|
|
185 |
timeSlider.stop().animate( |
|
|
186 |
calculateSliderCss(_height), |
|
|
187 |
500, |
|
|
188 |
function() { |
|
|
189 |
IriSP.jQuery(this).css("overflow","visible"); |
|
|
190 |
}); |
|
|
191 |
timeSliderHandle.stop().animate( |
|
|
192 |
calculateHandleCss(_height), |
|
|
193 |
500, |
|
|
194 |
function() { |
|
|
195 |
IriSP.jQuery(this).css("overflow","visible"); |
|
|
196 |
}); |
|
|
197 |
} |
|
|
198 |
|
|
|
199 |
function calculateSliderCss(_size) { |
|
|
200 |
return { |
|
|
201 |
height: _size + "px", |
|
|
202 |
"margin-top": (timeSliderMinimizedHeight - _size) + "px" |
|
|
203 |
}; |
|
|
204 |
} |
|
|
205 |
|
|
|
206 |
function calculateHandleCss(_size) { |
|
|
207 |
return { |
|
|
208 |
height: (2 + _size) + "px", |
|
|
209 |
width: (2 + _size) + "px", |
|
|
210 |
"margin-left": -Math.ceil(2 + _size / 2) + "px" |
|
18
|
211 |
} |
|
22
|
212 |
} |
|
|
213 |
|
|
|
214 |
/* Controller Widget */ |
|
|
215 |
|
|
|
216 |
var volBlock = $(".Ldt-Ctrl-Volume-Control"); |
|
25
|
217 |
|
|
22
|
218 |
$('.Ldt-Ctrl-Sound') |
|
25
|
219 |
.click(function() { |
|
|
220 |
if (currentMedia) { |
|
|
221 |
currentMedia.setMuted(!currentMedia.getMuted()); |
|
|
222 |
} |
|
|
223 |
}) |
|
22
|
224 |
.mouseover(function() { |
|
|
225 |
volBlock.show(); |
|
|
226 |
}) |
|
|
227 |
.mouseout(function() { |
|
|
228 |
volBlock.hide(); |
|
18
|
229 |
}); |
|
22
|
230 |
volBlock.mouseover(function() { |
|
|
231 |
volBlock.show(); |
|
|
232 |
}).mouseout(function() { |
|
|
233 |
volBlock.hide(); |
|
|
234 |
}); |
|
|
235 |
|
|
|
236 |
var volBar = $(".Ldt-Ctrl-Volume-Bar"); |
|
25
|
237 |
|
|
|
238 |
function ctrlVolumeUpdater() { |
|
|
239 |
if (currentMedia) { |
|
|
240 |
var _muted = currentMedia.getMuted(), |
|
|
241 |
_vol = currentMedia.getVolume(); |
|
|
242 |
if (_vol === false) { |
|
|
243 |
_vol = .5; |
|
|
244 |
} |
|
|
245 |
var _soundCtl = $(".Ldt-Ctrl-Sound"); |
|
|
246 |
_soundCtl.removeClass("Ldt-Ctrl-Sound-Mute Ldt-Ctrl-Sound-Half Ldt-Ctrl-Sound-Full"); |
|
|
247 |
if (_muted) { |
|
|
248 |
_soundCtl.attr("title", "Activer le son") |
|
|
249 |
.addClass("Ldt-Ctrl-Sound-Mute"); |
|
|
250 |
} else { |
|
|
251 |
_soundCtl.attr("title", "Couper le son") |
|
|
252 |
.addClass(_vol < .5 ? "Ldt-Ctrl-Sound-Half" : "Ldt-Ctrl-Sound-Full" ) |
|
|
253 |
} |
|
|
254 |
volBar.slider("value", _muted ? 0 : 100 * _vol); |
|
|
255 |
volBar.attr("title",'Volume : ' + Math.floor(100 * _vol) + '%'); |
|
|
256 |
} |
|
|
257 |
} |
|
|
258 |
|
|
22
|
259 |
volBar.slider({ |
|
|
260 |
slide: function(event, ui) { |
|
25
|
261 |
if (currentMedia) { |
|
|
262 |
currentMedia.setVolume(ui.value / 100); |
|
|
263 |
} |
|
22
|
264 |
} |
|
|
265 |
}); |
|
|
266 |
|
|
23
|
267 |
$(".Ldt-Ctrl-Play").click(function() { |
|
|
268 |
if (currentMedia) { |
|
|
269 |
if (currentMedia.getPaused()) { |
|
|
270 |
currentMedia.play(); |
|
|
271 |
} else { |
|
|
272 |
currentMedia.pause(); |
|
|
273 |
} |
|
|
274 |
} |
|
|
275 |
}); |
|
|
276 |
|
|
25
|
277 |
$(".Ldt-Ctrl-SetIn").click(function() { |
|
27
|
278 |
if (currentMedia && currentSegment) { |
|
|
279 |
currentSegment.setBegin(currentMedia.getCurrentTime()); |
|
25
|
280 |
} |
|
|
281 |
}); |
|
|
282 |
$(".Ldt-Ctrl-SetOut").click(function() { |
|
27
|
283 |
if (currentMedia && currentSegment) { |
|
|
284 |
currentSegment.setEnd(currentMedia.getCurrentTime()); |
|
25
|
285 |
} |
|
|
286 |
}); |
|
|
287 |
|
|
23
|
288 |
/* Slice Widget */ |
|
25
|
289 |
|
|
23
|
290 |
var sliceSlider = $(".Ldt-Slice"), |
|
|
291 |
sliceStartTime; |
|
|
292 |
|
|
|
293 |
sliceSlider.slider({ |
|
|
294 |
range: true, |
|
|
295 |
values: [0, slidersRange], |
|
|
296 |
min: 0, |
|
|
297 |
max: slidersRange, |
|
|
298 |
start: function() { |
|
|
299 |
if (currentMedia) { |
|
|
300 |
if (!currentMedia.getPaused()) { |
|
|
301 |
currentMedia.pause(); |
|
|
302 |
} |
|
|
303 |
} |
|
|
304 |
}, |
|
|
305 |
slide: function(event, ui) { |
|
27
|
306 |
if (currentMedia && currentSegment) { |
|
23
|
307 |
var t = currentMedia.duration * ui.value / slidersRange; |
|
25
|
308 |
if (ui.value === ui.values[0]) { |
|
27
|
309 |
currentSegment.setBegin(t); |
|
25
|
310 |
} else { |
|
27
|
311 |
currentSegment.setEnd(t); |
|
25
|
312 |
} |
|
23
|
313 |
} |
|
|
314 |
} |
|
|
315 |
}); |
|
|
316 |
|
|
25
|
317 |
sliceSlider.find(".ui-slider-handle:first") |
|
|
318 |
.addClass("Ldt-Slice-left-handle") |
|
|
319 |
.click(function() { |
|
27
|
320 |
if (currentMedia && currentSegment) { |
|
|
321 |
currentMedia.setCurrentTime(currentSegment.begin); |
|
25
|
322 |
} |
|
|
323 |
}); |
|
|
324 |
sliceSlider.find(".ui-slider-handle:last") |
|
|
325 |
.addClass("Ldt-Slice-right-handle") |
|
|
326 |
.click(function() { |
|
27
|
327 |
if (currentMedia && currentSegment) { |
|
|
328 |
currentMedia.setCurrentTime(currentSegment.end); |
|
25
|
329 |
} |
|
|
330 |
}); |
|
23
|
331 |
|
|
|
332 |
/* UI Events */ |
|
|
333 |
|
|
|
334 |
function onCurrentMediaPlay() { |
|
|
335 |
$(".Ldt-Ctrl-Play") |
|
|
336 |
.attr("title", "Pause") |
|
|
337 |
.removeClass("Ldt-Ctrl-Play-PlayState") |
|
|
338 |
.addClass("Ldt-Ctrl-Play-PauseState") |
|
|
339 |
} |
|
|
340 |
|
|
|
341 |
function onCurrentMediaPause() { |
|
|
342 |
$(".Ldt-Ctrl-Play") |
|
|
343 |
.attr("title", "Lecture") |
|
|
344 |
.removeClass("Ldt-Ctrl-Play-PauseState") |
|
|
345 |
.addClass("Ldt-Ctrl-Play-PlayState") |
|
|
346 |
} |
|
|
347 |
|
|
|
348 |
function onCurrentMediaTimeupdate(_time) { |
|
|
349 |
$(".Ldt-Ctrl-Time-Elapsed").text(_time.toString()); |
|
|
350 |
timeSlider.slider("value",slidersRange * _time / currentMedia.duration); |
|
|
351 |
} |
|
|
352 |
|
|
27
|
353 |
/* Mashup Player */ |
|
|
354 |
|
|
|
355 |
var mashupCurrentMedia = null, |
|
|
356 |
mashupCurrentAnnotation = null, |
|
|
357 |
mashupSegmentBegin, |
|
|
358 |
mashupSegmentEnd, |
|
|
359 |
mashupTimecode = 0, |
|
|
360 |
mashupSeeking = false, |
|
|
361 |
mashupSeekdiv, |
|
|
362 |
mashupTimedelta; |
|
|
363 |
|
|
|
364 |
function changeCurrentAnnotation() { |
|
|
365 |
if (mashupTimecode >= mashup.duration) { |
|
|
366 |
if (!mashup.paused) { |
|
|
367 |
mashup.paused = true; |
|
|
368 |
mashup.trigger("pause"); |
|
|
369 |
} |
|
|
370 |
mashupTimecode = 0; |
|
|
371 |
} |
|
|
372 |
var _annotation = mashup.getAnnotationAtTime( mashupTimecode ); |
|
|
373 |
if (typeof _annotation === "undefined") { |
|
|
374 |
if (mashupCurrentMedia) { |
|
|
375 |
mashupCurrentMedia.pause(); |
|
|
376 |
if (!mashup.paused) { |
|
|
377 |
mashup.paused = true; |
|
|
378 |
mashup.trigger("pause"); |
|
|
379 |
} |
|
|
380 |
} |
|
|
381 |
return; |
|
|
382 |
} |
|
|
383 |
mashupCurrentAnnotation = _annotation; |
|
|
384 |
mashupSegmentBegin = mashupCurrentAnnotation.annotation.begin.milliseconds; |
|
|
385 |
mashupSegmentEnd = mashupCurrentAnnotation.annotation.end.milliseconds; |
|
|
386 |
mashupTimedelta = mashupSegmentBegin - mashupCurrentAnnotation.begin.milliseconds; |
|
|
387 |
mashupCurrentMedia = mashupCurrentAnnotation.getMedia(); |
|
|
388 |
|
|
|
389 |
project.getMedias().forEach(function(_media) { |
|
|
390 |
if (_media !== mashupCurrentMedia) { |
|
|
391 |
_media.hide(); |
|
|
392 |
_media.pause(); |
|
|
393 |
} else { |
|
|
394 |
_media.show(); |
|
|
395 |
} |
|
|
396 |
}); |
|
|
397 |
|
|
|
398 |
mashupCurrentMedia.setCurrentTime( mashupTimecode + mashupTimedelta); |
|
|
399 |
mashupCurrentMedia.seeking = true; |
|
|
400 |
|
|
|
401 |
if (!mashup.paused) { |
|
|
402 |
mashupCurrentMedia.play(); |
|
|
403 |
mashupSeeking = true; |
|
|
404 |
//TODO: _seekdiv.show(); |
|
|
405 |
} |
|
|
406 |
mashup.trigger("timeupdate", new IriSP.Model.Time(mashupTimecode)); |
|
|
407 |
|
|
|
408 |
} |
|
|
409 |
|
|
22
|
410 |
/* Set current Media */ |
|
25
|
411 |
|
|
27
|
412 |
var currentMedia, currentSegment; |
|
22
|
413 |
|
|
25
|
414 |
function updateSliderAndTangles() { |
|
27
|
415 |
if (currentMedia && currentSegment) { |
|
|
416 |
var start = currentSegment.begin, |
|
|
417 |
end = currentSegment.end, |
|
|
418 |
dur = currentSegment.getDuration(), |
|
|
419 |
f = slidersRange / currentMedia.duration, |
|
|
420 |
tangleStart = $(".tangle-start"), |
|
|
421 |
tangleEnd = $(".tangle-end"), |
|
|
422 |
tangleDuration = $(".tangle-duration"); |
|
25
|
423 |
sliceSlider.slider( "values", [ f * start, f * end ] ); |
|
27
|
424 |
tangleStart.text(start.toString(tangleStart.hasClass("active"))).attr("data-milliseconds",start.milliseconds); |
|
|
425 |
tangleEnd.text(end.toString(tangleEnd.hasClass("active"))).attr("data-milliseconds",end.milliseconds); |
|
|
426 |
tangleDuration.text(dur.toString(tangleDuration.hasClass("active"))).attr("data-milliseconds",dur.milliseconds); |
|
25
|
427 |
$(".segment-info .pointer").css("left",(parseFloat($(".Ldt-Slice-left-handle").css("left")) + parseFloat($(".Ldt-Slice-right-handle").css("left")))/2) |
|
|
428 |
} |
|
|
429 |
} |
|
|
430 |
|
|
27
|
431 |
var addMode; |
|
|
432 |
|
|
|
433 |
function setMedia(media) { |
|
23
|
434 |
$(".col-left .item-video").removeClass("active"); |
|
|
435 |
$(".tutorial").hide(); |
|
|
436 |
if (currentMedia) { |
|
|
437 |
currentMedia.pause(); |
|
|
438 |
} |
|
27
|
439 |
currentMedia = media; |
|
22
|
440 |
if (currentMedia.elementType == "media") { |
|
27
|
441 |
$("video").hide(); |
|
|
442 |
$(".col-left .item-video[data-media-id='" + currentMedia.id + "']").addClass("active"); |
|
23
|
443 |
showSegmentation(); |
|
27
|
444 |
var currentvideo = $('#video_' + currentMedia.id); |
|
23
|
445 |
if (!currentvideo.length) { |
|
|
446 |
addMediaPlayer(currentMedia); |
|
|
447 |
} |
|
|
448 |
$(".tab-media-title").text(currentMedia.title); |
|
27
|
449 |
|
|
|
450 |
addMode = !(currentSegment && mashup.hasAnnotation(currentSegment)); |
|
|
451 |
|
|
|
452 |
if (!currentSegment) { |
|
|
453 |
currentSegment = new IriSP.Model.Annotation(false, project); |
|
|
454 |
currentSegment.setMedia(currentMedia.id); |
|
|
455 |
currentSegment.setBegin(0); |
|
|
456 |
currentSegment.setEnd(currentMedia.duration); |
|
|
457 |
currentSegment.title = "Segment sans titre"; |
|
|
458 |
currentSegment.description = "Extrait de « " + currentMedia.title + " »"; |
|
|
459 |
currentSegment.on("change-begin", function() { |
|
|
460 |
if (currentMedia && currentSegment === this) { |
|
25
|
461 |
currentMedia.setCurrentTime(this.begin); |
|
|
462 |
updateSliderAndTangles(); |
|
|
463 |
} |
|
|
464 |
}); |
|
27
|
465 |
currentSegment.on("change-end", function() { |
|
|
466 |
if (currentMedia && currentSegment === this) { |
|
25
|
467 |
currentMedia.setCurrentTime(this.end); |
|
|
468 |
updateSliderAndTangles(); |
|
|
469 |
} |
|
|
470 |
}); |
|
27
|
471 |
currentSegment.on("enter", function() { |
|
|
472 |
if (currentMedia === mashup) { |
|
|
473 |
$(".annotation-title").text(this.title); |
|
|
474 |
$(".annotation-begin").text(this.begin.toString()); |
|
|
475 |
$(".annotation-end").text(this.end.toString()); |
|
|
476 |
$(".annotation-media-title").text(this.getMedia().title); |
|
|
477 |
$(".annotation-description").text(this.description); |
|
|
478 |
setPointerToCurrentAnnotation(); |
|
|
479 |
} |
|
|
480 |
}) |
|
25
|
481 |
} |
|
27
|
482 |
if (currentMedia.loaded) { |
|
|
483 |
currentMedia.setCurrentTime(currentSegment.begin); |
|
|
484 |
} |
|
|
485 |
$(".add-segment").val(addMode ? "Ajouter au Hashcut" : "Sauvegarder"); |
|
|
486 |
$(".create-or-edit").text(addMode ? "Créer un nouveau segment" : "Modifier le segment"); |
|
25
|
487 |
updateSliderAndTangles(); |
|
27
|
488 |
media.show(); |
|
|
489 |
$("#segment-title").val(currentSegment.title); |
|
|
490 |
$("#segment-description").val(currentSegment.description); |
|
|
491 |
$("#segment-tags").val(""); |
|
22
|
492 |
} |
|
27
|
493 |
if (currentMedia.elementType === "mashup") { |
|
|
494 |
showPreview(); |
|
|
495 |
mashup.checkLoaded(); |
|
|
496 |
} |
|
23
|
497 |
$(".Ldt-Ctrl-Time-Total").text(currentMedia.duration.toString()); |
|
25
|
498 |
// TODO: Do something with the tags ! |
|
23
|
499 |
onCurrentMediaTimeupdate(currentMedia.getCurrentTime()); |
|
|
500 |
onCurrentMediaPause(); |
|
27
|
501 |
highlightCurrentSegment(); |
|
22
|
502 |
} |
|
|
503 |
|
|
|
504 |
function addMediaPlayer(media) { |
|
23
|
505 |
var videoid = "video_" + media.id, |
|
|
506 |
videoEl = $('<video>'), |
|
|
507 |
width = $(".video").width(), |
|
|
508 |
height = $(".video").height(), |
|
|
509 |
mp4_file = media.video.replace(/\.webm$/i,'.mp4'), |
|
|
510 |
webm_file = media.video.replace(/\.mp4$/i,'.webm'), |
|
|
511 |
mp4_src = $('<source>'), |
|
|
512 |
webm_src = $('<source>'); |
|
|
513 |
mp4_src.attr({ |
|
|
514 |
src: mp4_file, |
|
|
515 |
type: "video/mp4" |
|
|
516 |
}); |
|
|
517 |
webm_src.attr({ |
|
|
518 |
src: webm_file, |
|
|
519 |
type: "video/webm" |
|
|
520 |
}); |
|
|
521 |
videoEl.attr({ |
|
|
522 |
id : videoid, |
|
|
523 |
width : width, |
|
|
524 |
height : height |
|
|
525 |
}).css({ |
|
|
526 |
position : "absolute", |
|
|
527 |
left: 0, |
|
|
528 |
top: 0, |
|
|
529 |
width : width, |
|
|
530 |
height : height |
|
|
531 |
}); |
|
|
532 |
videoEl.append(mp4_src).append(webm_src); |
|
|
533 |
$(".video").append(videoEl); |
|
27
|
534 |
|
|
|
535 |
media.show = function() { |
|
|
536 |
videoEl.show(); |
|
|
537 |
} |
|
|
538 |
media.hide = function() { |
|
|
539 |
videoEl.hide(); |
|
|
540 |
} |
|
|
541 |
|
|
23
|
542 |
var popcorn = Popcorn("#" + videoid); |
|
|
543 |
|
|
|
544 |
// Binding functions to Popcorn |
|
|
545 |
|
|
|
546 |
media.on("setcurrenttime", function(_milliseconds) { |
|
27
|
547 |
if (media.loaded) { |
|
|
548 |
popcorn.currentTime(_milliseconds / 1000); |
|
|
549 |
} |
|
23
|
550 |
}); |
|
|
551 |
|
|
|
552 |
media.on("setvolume", function(_vol) { |
|
|
553 |
media.volume = _vol; |
|
27
|
554 |
if (media.loaded) { |
|
|
555 |
popcorn.volume(_vol); |
|
|
556 |
} |
|
23
|
557 |
}); |
|
|
558 |
|
|
|
559 |
media.on("setmuted", function(_muted) { |
|
|
560 |
media.muted = _muted; |
|
27
|
561 |
if (media.loaded) { |
|
|
562 |
popcorn.muted(_muted); |
|
|
563 |
} |
|
23
|
564 |
}); |
|
|
565 |
|
|
|
566 |
media.on("setplay", function() { |
|
27
|
567 |
if (media.loaded) { |
|
|
568 |
popcorn.play(); |
|
|
569 |
} |
|
23
|
570 |
}); |
|
|
571 |
|
|
|
572 |
media.on("setpause", function() { |
|
27
|
573 |
if (media.loaded) { |
|
|
574 |
popcorn.pause(); |
|
|
575 |
} |
|
23
|
576 |
}); |
|
|
577 |
|
|
|
578 |
// Binding Popcorn events to media |
|
|
579 |
|
|
|
580 |
function getVolume() { |
|
|
581 |
media.muted = popcorn.muted(); |
|
|
582 |
media.volume = popcorn.volume(); |
|
|
583 |
} |
|
|
584 |
|
|
|
585 |
popcorn.on("loadedmetadata", function() { |
|
|
586 |
getVolume(); |
|
27
|
587 |
media.loaded = true; |
|
23
|
588 |
media.trigger("loadedmetadata"); |
|
|
589 |
media.trigger("volumechange"); |
|
|
590 |
}) |
|
|
591 |
|
|
|
592 |
popcorn.on("timeupdate", function() { |
|
|
593 |
media.trigger("timeupdate", new IriSP.Model.Time(1000*popcorn.currentTime())); |
|
|
594 |
}); |
|
|
595 |
|
|
|
596 |
popcorn.on("volumechange", function() { |
|
|
597 |
getVolume(); |
|
|
598 |
media.trigger("volumechange"); |
|
|
599 |
}) |
|
|
600 |
|
|
|
601 |
popcorn.on("play", function() { |
|
|
602 |
media.trigger("play"); |
|
|
603 |
}); |
|
|
604 |
|
|
|
605 |
popcorn.on("pause", function() { |
|
|
606 |
media.trigger("pause"); |
|
|
607 |
}); |
|
|
608 |
|
|
|
609 |
popcorn.on("seeked", function() { |
|
|
610 |
media.trigger("seeked"); |
|
|
611 |
}); |
|
|
612 |
|
|
27
|
613 |
// Binding UI Events and Mashup Playing to Media |
|
|
614 |
|
|
|
615 |
media.on("loadedmetadata", function() { |
|
|
616 |
mashup.checkLoaded(); |
|
|
617 |
}); |
|
23
|
618 |
|
|
|
619 |
media.on("play", function() { |
|
|
620 |
if (media === currentMedia) { |
|
|
621 |
onCurrentMediaPlay(); |
|
|
622 |
} |
|
27
|
623 |
if (mashup === currentMedia && media === mashupCurrentMedia) { |
|
|
624 |
mashup.trigger("play"); |
|
|
625 |
} |
|
23
|
626 |
}); |
|
|
627 |
|
|
|
628 |
media.on("pause", function() { |
|
|
629 |
if (media === currentMedia) { |
|
|
630 |
onCurrentMediaPause(); |
|
|
631 |
} |
|
27
|
632 |
if (mashup === currentMedia && media === mashupCurrentMedia) { |
|
|
633 |
mashup.trigger("pause"); |
|
|
634 |
} |
|
23
|
635 |
}); |
|
|
636 |
|
|
|
637 |
media.on("timeupdate", function(_time) { |
|
|
638 |
if (media === currentMedia) { |
|
|
639 |
onCurrentMediaTimeupdate(_time); |
|
|
640 |
} |
|
27
|
641 |
if (mashup === currentMedia && !mashup.paused && media === mashupCurrentMedia && !media.seeking) { |
|
|
642 |
if ( _time < mashupSegmentEnd ) { |
|
|
643 |
if ( _time >= mashupSegmentBegin ) { |
|
|
644 |
mashupTimecode = _time - mashupTimedelta; |
|
|
645 |
} else { |
|
|
646 |
mashupTimecode = mashupSegmentBegin - mashupTimedelta; |
|
|
647 |
media.setCurrentTime(mashupSegmentBegin); |
|
|
648 |
} |
|
|
649 |
} else { |
|
|
650 |
mashupTimecode = mashupSegmentEnd - mashupTimedelta; |
|
|
651 |
media.pause(); |
|
|
652 |
changeCurrentAnnotation(); |
|
|
653 |
} |
|
|
654 |
mashup.trigger("timeupdate", new IriSP.Model.Time(mashupTimecode)); |
|
|
655 |
} |
|
|
656 |
}); |
|
|
657 |
|
|
|
658 |
media.on("seeked", function() { |
|
|
659 |
media.seeking = false; |
|
|
660 |
if (mashup === currentMedia && media === mashupCurrentMedia && mashupSeeking) { |
|
|
661 |
mashupSeeking = false; |
|
|
662 |
//TODO: _seekdiv.hide(); |
|
|
663 |
} |
|
25
|
664 |
}); |
|
|
665 |
|
|
|
666 |
media.on("volumechange", function() { |
|
|
667 |
if (media === currentMedia) { |
|
|
668 |
ctrlVolumeUpdater(); |
|
|
669 |
} |
|
27
|
670 |
mashup.muted = media.muted; |
|
|
671 |
mashup.volume = media.volume; |
|
|
672 |
mashup.trigger("volumechange"); |
|
23
|
673 |
}) |
|
18
|
674 |
|
|
13
|
675 |
} |
|
27
|
676 |
|
|
|
677 |
// Mashup Events |
|
25
|
678 |
|
|
27
|
679 |
mashup.on("setcurrenttime", function(_milliseconds) { |
|
|
680 |
mashupTimecode = _milliseconds; |
|
|
681 |
changeCurrentAnnotation(); |
|
|
682 |
}); |
|
|
683 |
|
|
|
684 |
mashup.on("setvolume", function(_vol) { |
|
|
685 |
mashup.getMedias().forEach(function(_media) { |
|
|
686 |
_media.setVolume(_vol); |
|
|
687 |
}); |
|
|
688 |
mashup.volume = _vol; |
|
|
689 |
}); |
|
|
690 |
|
|
|
691 |
mashup.on("setmuted", function(_muted) { |
|
|
692 |
mashup.getMedias().forEach(function(_media) { |
|
|
693 |
_media.setMuted(_muted); |
|
|
694 |
}); |
|
|
695 |
mashup.muted = _muted; |
|
|
696 |
}); |
|
|
697 |
|
|
|
698 |
mashup.on("setplay", function() { |
|
|
699 |
mashup.paused = false; |
|
|
700 |
changeCurrentAnnotation(); |
|
|
701 |
}); |
|
|
702 |
|
|
|
703 |
mashup.on("setpause", function() { |
|
|
704 |
mashup.paused = true; |
|
|
705 |
if (mashupCurrentMedia) { |
|
|
706 |
mashupCurrentMedia.pause(); |
|
|
707 |
} |
|
|
708 |
}); |
|
|
709 |
|
|
|
710 |
mashup.on("loadedmetadata", function() { |
|
|
711 |
if (mashup === currentMedia) { |
|
|
712 |
changeCurrentAnnotation(); |
|
|
713 |
} |
|
|
714 |
}); |
|
|
715 |
|
|
|
716 |
/* Mashup Events to UI */ |
|
|
717 |
|
|
|
718 |
mashup.on("play", function() { |
|
|
719 |
if (mashup === currentMedia) { |
|
|
720 |
onCurrentMediaPlay(); |
|
|
721 |
} |
|
|
722 |
}); |
|
|
723 |
|
|
|
724 |
mashup.on("pause", function() { |
|
|
725 |
if (mashup === currentMedia) { |
|
|
726 |
onCurrentMediaPause(); |
|
|
727 |
} |
|
|
728 |
}); |
|
|
729 |
|
|
|
730 |
mashup.on("timeupdate", function(_time) { |
|
|
731 |
if (mashup === currentMedia) { |
|
|
732 |
$(".frise-position").css("left",(100*_time/mashup.duration)+"%"); |
|
|
733 |
onCurrentMediaTimeupdate(_time); |
|
|
734 |
} |
|
|
735 |
}); |
|
|
736 |
|
|
25
|
737 |
/* Segment Form interaction */ |
|
|
738 |
|
|
|
739 |
$("#segment-title").on("keyup change input paste", function() { |
|
27
|
740 |
if (currentMedia && currentSegment) { |
|
|
741 |
currentSegment.title = $(this).val(); |
|
|
742 |
updateMashupUI(); |
|
25
|
743 |
} |
|
|
744 |
}); |
|
|
745 |
$("#segment-description").on("keyup change input paste", function() { |
|
27
|
746 |
if (currentMedia && currentSegment) { |
|
|
747 |
currentSegment.description = $(this).val(); |
|
25
|
748 |
} |
|
|
749 |
}); |
|
|
750 |
$("#segment-form").submit(function() { |
|
27
|
751 |
if (addMode) { |
|
|
752 |
mashup.addAnnotation(currentSegment); |
|
|
753 |
} else { |
|
|
754 |
updateMashupUI(); |
|
|
755 |
} |
|
|
756 |
var segment = mashup.getAnnotation(currentSegment); |
|
|
757 |
currentSegment = undefined; |
|
|
758 |
setMedia(mashup); |
|
|
759 |
if (segment) { |
|
|
760 |
mashup.setCurrentTime(segment.begin); |
|
|
761 |
} |
|
25
|
762 |
}) |
|
|
763 |
|
|
22
|
764 |
/* Click on media items */ |
|
|
765 |
|
|
|
766 |
$(".col-left").on("click", ".item-video", function() { |
|
27
|
767 |
currentSegment = undefined; |
|
|
768 |
setMedia(project.getElement($(this).attr("data-media-id"))); |
|
22
|
769 |
}); |
|
12
|
770 |
|
|
22
|
771 |
/* Click on Tabs */ |
|
|
772 |
|
|
|
773 |
function showSegmentation() { |
|
|
774 |
$(".col-middle").removeClass("empty-mode pvw-mode").addClass("segment-mode"); |
|
|
775 |
return false; |
|
|
776 |
} |
|
|
777 |
function showPreview() { |
|
|
778 |
$(".col-middle").removeClass("empty-mode segment-mode").addClass("pvw-mode"); |
|
|
779 |
return false; |
|
|
780 |
} |
|
|
781 |
|
|
27
|
782 |
$(".tab-pvw").click(function() { |
|
|
783 |
if (mashup.segments.length) { |
|
|
784 |
setMedia(mashup); |
|
22
|
785 |
} |
|
|
786 |
}); |
|
|
787 |
|
|
27
|
788 |
/* Click on segments */ |
|
|
789 |
|
|
|
790 |
function reorganizeMashup() { |
|
|
791 |
var ids = $(".organize-segments .item-video").map(function(){return $(this).attr("data-segment-id")}); |
|
|
792 |
mashup.setAnnotationsById(ids); |
|
|
793 |
} |
|
|
794 |
|
|
|
795 |
function highlightCurrentSegment() { |
|
|
796 |
$(".organize-segments .item-video").removeClass("active"); |
|
|
797 |
if (currentMedia && currentSegment) { |
|
|
798 |
$(".item-video[data-segment-id='" + currentSegment.id + "']").addClass("active"); |
|
|
799 |
} |
|
|
800 |
} |
|
|
801 |
|
|
|
802 |
$(".organize-segments").sortable({ |
|
|
803 |
stop : reorganizeMashup |
|
|
804 |
}); |
|
|
805 |
|
|
|
806 |
$(".organize-segments").on("click", ".item-video", function(e) { |
|
|
807 |
var el = $(this), |
|
|
808 |
segment = mashup.getAnnotationById(el.attr("data-segment-id")); |
|
|
809 |
setMedia(mashup); |
|
|
810 |
if (segment) { |
|
|
811 |
mashup.setCurrentTime(segment.begin); |
|
|
812 |
} |
|
|
813 |
return false; |
|
|
814 |
}); |
|
|
815 |
|
|
|
816 |
$(".organize-segments").on("click", ".edit", function(e) { |
|
|
817 |
var currentItem = $(this).parents(".item-video"), |
|
|
818 |
media = project.getElement(currentItem.attr("data-media-id")), |
|
|
819 |
segment = project.getElement(currentItem.attr("data-segment-id")); |
|
|
820 |
currentSegment = segment; |
|
|
821 |
setMedia(media); |
|
|
822 |
return false; |
|
|
823 |
}); |
|
|
824 |
|
|
|
825 |
$(".organize-segments").on("click", ".top", function(e){ |
|
22
|
826 |
var currentItem = $(this).parents(".item-video"); |
|
|
827 |
currentItem.insertBefore(currentItem.prev()); |
|
27
|
828 |
reorganizeMashup(); |
|
|
829 |
return false; |
|
22
|
830 |
}); |
|
|
831 |
|
|
27
|
832 |
$(".organize-segments").on("click", ".bottom", function(e){ |
|
22
|
833 |
var currentItem = $(this).parents(".item-video"); |
|
|
834 |
currentItem.insertAfter(currentItem.next()); |
|
27
|
835 |
reorganizeMashup(); |
|
|
836 |
return false; |
|
|
837 |
}); |
|
|
838 |
|
|
|
839 |
$(".organize-segments").on("click", ".delete", function(e){ |
|
|
840 |
var id = $(this).parents(".item-video").attr("data-segment-id"); |
|
|
841 |
mashup.removeAnnotationById(id); |
|
|
842 |
return false; |
|
22
|
843 |
}); |
|
|
844 |
|
|
25
|
845 |
/* Tangles */ |
|
|
846 |
var tangleMsPerPixel = 100, |
|
|
847 |
activeTangle, |
|
23
|
848 |
tangleStartX, |
|
25
|
849 |
tangleStartVal, |
|
|
850 |
tangleHasMoved; |
|
|
851 |
|
|
23
|
852 |
$(".time-tangle").mousedown(function(evt) { |
|
|
853 |
activeTangle = $(this); |
|
|
854 |
activeTangle.addClass("active"); |
|
|
855 |
tangleStartVal = +activeTangle.attr("data-milliseconds"); |
|
|
856 |
tangleStartX = evt.pageX; |
|
25
|
857 |
tangleHasMoved = false; |
|
|
858 |
$(this).siblings(".time-tangle").addClass("deactivate"); |
|
23
|
859 |
return false; |
|
|
860 |
}); |
|
|
861 |
$(document) |
|
|
862 |
.mousemove(function(evt) { |
|
|
863 |
if (activeTangle) { |
|
25
|
864 |
tangleHasMoved = true; |
|
|
865 |
var newval = new IriSP.Model.Time(tangleMsPerPixel * (evt.pageX - tangleStartX) + tangleStartVal); |
|
23
|
866 |
activeTangle.trigger("valuechange", newval); |
|
|
867 |
return false; |
|
|
868 |
} |
|
|
869 |
}) |
|
|
870 |
.mouseup(function() { |
|
|
871 |
if (activeTangle) { |
|
27
|
872 |
activeTangle.text(activeTangle.text().replace(/\.\d+$/,'')); |
|
25
|
873 |
$(".time-tangle").removeClass("active deactivate"); |
|
23
|
874 |
activeTangle = undefined; |
|
|
875 |
} |
|
25
|
876 |
}); |
|
|
877 |
|
|
|
878 |
$(".tangle-start") |
|
|
879 |
.mouseup(function(evt) { |
|
27
|
880 |
if (!tangleHasMoved && currentMedia && currentSegment) { |
|
|
881 |
currentMedia.setCurrentTime(currentSegment.begin); |
|
25
|
882 |
} |
|
23
|
883 |
}) |
|
25
|
884 |
.on("valuechange", function(evt, val) { |
|
27
|
885 |
if (currentMedia && currentSegment) { |
|
|
886 |
currentSegment.setBegin(val); |
|
25
|
887 |
} |
|
|
888 |
}); |
|
|
889 |
$(".tangle-end") |
|
|
890 |
.mouseup(function(evt) { |
|
27
|
891 |
if (!tangleHasMoved && currentMedia && currentSegment) { |
|
|
892 |
currentMedia.setCurrentTime(currentSegment.end); |
|
25
|
893 |
} |
|
|
894 |
}) |
|
|
895 |
.on("valuechange", function(evt, val) { |
|
27
|
896 |
if (currentMedia && currentSegment) { |
|
|
897 |
currentSegment.setEnd(val); |
|
25
|
898 |
} |
|
|
899 |
}); |
|
|
900 |
$(".tangle-duration").on("valuechange", function(evt, val) { |
|
27
|
901 |
if (currentMedia && currentSegment) { |
|
|
902 |
currentSegment.setDuration(val); |
|
25
|
903 |
} |
|
|
904 |
}); |
|
27
|
905 |
|
|
|
906 |
$(".mashup-description .edit").click(function() { |
|
|
907 |
if (mashupCurrentAnnotation) { |
|
|
908 |
currentSegment = mashupCurrentAnnotation.annotation; |
|
|
909 |
setMedia(mashupCurrentAnnotation.getMedia()); |
|
|
910 |
} |
|
|
911 |
}) |
|
13
|
912 |
} |