5 var directory = new IriSP.Model.Directory(), |
5 var directory = new IriSP.Model.Directory(), |
6 project = directory.remoteSource({ |
6 project = directory.remoteSource({ |
7 url: "data/bpidata.json", |
7 url: "data/bpidata.json", |
8 serializer: IriSP.serializers.medialist |
8 serializer: IriSP.serializers.medialist |
9 }), |
9 }), |
|
10 mashup = new IriSP.Model.Mashup(false, project), |
10 mediatemplate = '<li class="item-video" data-media-id="{{id}}"><img src="{{thumbnail}}" alt="{{title}}" />' |
11 mediatemplate = '<li class="item-video" data-media-id="{{id}}"><img src="{{thumbnail}}" alt="{{title}}" />' |
11 + '<span class="video-info"><span class="title-video">{{title}}</span><span class="author">{{description}}</span>' |
12 + '<span class="video-info"><span class="title-video">{{title}}</span><span class="author">{{description}}</span>' |
12 + '<span class="time-length">Durée : <span>{{duration}}</span></span></span></li>'; |
13 + '<span class="time-length">Durée : <span>{{duration}}</span></span></span></li>', |
|
14 segmenttemplate = '<li class="item-video" data-segment-id="{{id}}"><img src="{{annotation.thumbnail}}" alt="{{media_title}}" />' |
|
15 + '<span class="video-info"><span class="title-video">{{media_title}}</span>' |
|
16 + '<span class="subtitle">{{title}}</span><span class="duration">{{begin}} - {{end}} ({{duration}})</span>' |
|
17 + '<ul class="tools"><li><a class="edit" href="#"></a></li><li><a class="bottom" href="#"></a></li>' |
|
18 + '<li><a class="top" href="#"></a></li><li><a class="delete" href="#"></a></li></ul></span></li>'; |
13 |
19 |
14 /* Fill left column with Media List */ |
20 /* Fill left column with Media List */ |
15 |
21 |
16 project.onLoad(function() { |
22 project.onLoad(function() { |
17 var html = ''; |
23 var html = ''; |
18 project.getMedias().forEach(function(_m) { |
24 project.getMedias().forEach(function(_m) { |
19 html += Mustache.to_html(mediatemplate, _m); |
25 html += Mustache.to_html(mediatemplate, _m); |
20 }); |
26 }); |
163 }).mouseout(function() { |
186 }).mouseout(function() { |
164 volBlock.hide(); |
187 volBlock.hide(); |
165 }); |
188 }); |
166 |
189 |
167 var volBar = $(".Ldt-Ctrl-Volume-Bar"); |
190 var volBar = $(".Ldt-Ctrl-Volume-Bar"); |
|
191 |
|
192 function ctrlVolumeUpdater() { |
|
193 if (currentMedia) { |
|
194 var _muted = currentMedia.getMuted(), |
|
195 _vol = currentMedia.getVolume(); |
|
196 if (_vol === false) { |
|
197 _vol = .5; |
|
198 } |
|
199 var _soundCtl = $(".Ldt-Ctrl-Sound"); |
|
200 _soundCtl.removeClass("Ldt-Ctrl-Sound-Mute Ldt-Ctrl-Sound-Half Ldt-Ctrl-Sound-Full"); |
|
201 if (_muted) { |
|
202 _soundCtl.attr("title", "Activer le son") |
|
203 .addClass("Ldt-Ctrl-Sound-Mute"); |
|
204 } else { |
|
205 _soundCtl.attr("title", "Couper le son") |
|
206 .addClass(_vol < .5 ? "Ldt-Ctrl-Sound-Half" : "Ldt-Ctrl-Sound-Full" ) |
|
207 } |
|
208 volBar.slider("value", _muted ? 0 : 100 * _vol); |
|
209 volBar.attr("title",'Volume : ' + Math.floor(100 * _vol) + '%'); |
|
210 } |
|
211 } |
|
212 |
168 volBar.slider({ |
213 volBar.slider({ |
169 slide: function(event, ui) { |
214 slide: function(event, ui) { |
170 volBar.attr("title",'Volume : ' + ui.value + '%'); |
215 if (currentMedia) { |
171 //_this.media.setVolume(ui.value / 100); |
216 currentMedia.setVolume(ui.value / 100); |
172 }, |
217 } |
173 stop: function() { |
|
174 // IriSP.Widgets.Controller.prototype.volumeUpdater |
|
175 } |
218 } |
176 }); |
219 }); |
177 |
220 |
178 $(".Ldt-Ctrl-Play").click(function() { |
221 $(".Ldt-Ctrl-Play").click(function() { |
179 if (currentMedia) { |
222 if (currentMedia) { |
183 currentMedia.pause(); |
226 currentMedia.pause(); |
184 } |
227 } |
185 } |
228 } |
186 }); |
229 }); |
187 |
230 |
|
231 $(".Ldt-Ctrl-SetIn").click(function() { |
|
232 if (currentMedia && currentMedia.currentSegment) { |
|
233 currentMedia.currentSegment.setBegin(currentMedia.getCurrentTime()); |
|
234 } |
|
235 }); |
|
236 $(".Ldt-Ctrl-SetOut").click(function() { |
|
237 if (currentMedia && currentMedia.currentSegment) { |
|
238 currentMedia.currentSegment.setEnd(currentMedia.getCurrentTime()); |
|
239 } |
|
240 }); |
|
241 |
188 /* Slice Widget */ |
242 /* Slice Widget */ |
|
243 |
189 var sliceSlider = $(".Ldt-Slice"), |
244 var sliceSlider = $(".Ldt-Slice"), |
190 sliceStartTime; |
245 sliceStartTime; |
191 |
|
192 function setTangles(sliderValues) { |
|
193 //TODO: Move to Annotation.on("changebounds") |
|
194 if (currentMedia) { |
|
195 startTime = new IriSP.Model.Time(currentMedia.duration * sliderValues[0] / slidersRange), |
|
196 endTime = new IriSP.Model.Time(currentMedia.duration * sliderValues[1] / slidersRange), |
|
197 duration = new IriSP.Model.Time(endTime - startTime); |
|
198 $(".tangle-start").text(startTime.toString()).attr("data-milliseconds",startTime.milliseconds); |
|
199 $(".tangle-end").text(endTime.toString()).attr("data-milliseconds",endTime.milliseconds); |
|
200 $(".tangle-duration").text(duration.toString()).attr("data-milliseconds",duration.milliseconds); |
|
201 } |
|
202 } |
|
203 |
246 |
204 sliceSlider.slider({ |
247 sliceSlider.slider({ |
205 range: true, |
248 range: true, |
206 values: [0, slidersRange], |
249 values: [0, slidersRange], |
207 min: 0, |
250 min: 0, |
208 max: slidersRange, |
251 max: slidersRange, |
209 change: function(event, ui) { |
|
210 setTangles(ui.values); // Not the right place to put it |
|
211 }, |
|
212 start: function() { |
252 start: function() { |
213 if (currentMedia) { |
253 if (currentMedia) { |
214 if (!currentMedia.getPaused()) { |
254 if (!currentMedia.getPaused()) { |
215 currentMedia.pause(); |
255 currentMedia.pause(); |
216 } |
256 } |
217 // sliceStartTime = currentMedia.getCurrentTime(); |
|
218 } |
257 } |
219 }, |
258 }, |
220 slide: function(event, ui) { |
259 slide: function(event, ui) { |
221 if (currentMedia) { |
260 if (currentMedia && currentMedia.currentSegment) { |
222 var t = currentMedia.duration * ui.value / slidersRange; |
261 var t = currentMedia.duration * ui.value / slidersRange; |
223 currentMedia.setCurrentTime(t); |
262 if (ui.value === ui.values[0]) { |
224 } |
263 currentMedia.currentSegment.setBegin(t); |
225 setTangles(ui.values); |
264 } else { |
226 }, |
265 currentMedia.currentSegment.setEnd(t); |
227 stop: function() { |
266 } |
228 if (currentMedia && sliceStartTime) { |
267 } |
229 // currentMedia.setCurrentTime(sliceStartTime); |
268 } |
230 } |
269 }); |
231 } |
270 |
232 }); |
271 sliceSlider.find(".ui-slider-handle:first") |
233 |
272 .addClass("Ldt-Slice-left-handle") |
234 sliceSlider.find(".ui-slider-handle:first").addClass("Ldt-Slice-left-handle"); |
273 .click(function() { |
235 sliceSlider.find(".ui-slider-handle:last").addClass("Ldt-Slice-right-handle"); |
274 if (currentMedia && currentMedia.currentSegment) { |
|
275 currentMedia.setCurrentTime(currentMedia.currentSegment.begin); |
|
276 } |
|
277 }); |
|
278 sliceSlider.find(".ui-slider-handle:last") |
|
279 .addClass("Ldt-Slice-right-handle") |
|
280 .click(function() { |
|
281 if (currentMedia && currentMedia.currentSegment) { |
|
282 currentMedia.setCurrentTime(currentMedia.currentSegment.end); |
|
283 } |
|
284 }); |
236 |
285 |
237 /* UI Events */ |
286 /* UI Events */ |
238 |
287 |
239 function onCurrentMediaPlay() { |
288 function onCurrentMediaPlay() { |
240 $(".Ldt-Ctrl-Play") |
289 $(".Ldt-Ctrl-Play") |
254 $(".Ldt-Ctrl-Time-Elapsed").text(_time.toString()); |
303 $(".Ldt-Ctrl-Time-Elapsed").text(_time.toString()); |
255 timeSlider.slider("value",slidersRange * _time / currentMedia.duration); |
304 timeSlider.slider("value",slidersRange * _time / currentMedia.duration); |
256 } |
305 } |
257 |
306 |
258 /* Set current Media */ |
307 /* Set current Media */ |
|
308 |
259 var currentMedia; |
309 var currentMedia; |
|
310 |
|
311 function updateSliderAndTangles() { |
|
312 if (currentMedia && currentMedia.currentSegment) { |
|
313 var start = currentMedia.currentSegment.begin, |
|
314 end = currentMedia.currentSegment.end, |
|
315 dur = currentMedia.currentSegment.getDuration(), |
|
316 f = slidersRange / currentMedia.duration; |
|
317 sliceSlider.slider( "values", [ f * start, f * end ] ); |
|
318 $(".tangle-start").text(start.toString()).attr("data-milliseconds",start.milliseconds); |
|
319 $(".tangle-end").text(end.toString()).attr("data-milliseconds",end.milliseconds); |
|
320 $(".tangle-duration").text(dur.toString()).attr("data-milliseconds",dur.milliseconds); |
|
321 $(".segment-info .pointer").css("left",(parseFloat($(".Ldt-Slice-left-handle").css("left")) + parseFloat($(".Ldt-Slice-right-handle").css("left")))/2) |
|
322 } |
|
323 } |
260 |
324 |
261 function setMedia(mediaid) { |
325 function setMedia(mediaid) { |
262 $(".col-left .item-video").removeClass("active"); |
326 $(".col-left .item-video").removeClass("active"); |
263 $(".tutorial").hide(); |
327 $(".tutorial").hide(); |
264 $("video").hide(); |
328 $("video").hide(); |
273 if (!currentvideo.length) { |
337 if (!currentvideo.length) { |
274 addMediaPlayer(currentMedia); |
338 addMediaPlayer(currentMedia); |
275 currentvideo = $('#video_' + mediaid); |
339 currentvideo = $('#video_' + mediaid); |
276 } |
340 } |
277 $(".tab-media-title").text(currentMedia.title); |
341 $(".tab-media-title").text(currentMedia.title); |
278 sliceSlider.slider("values",[0, slidersRange]); |
342 if (!currentMedia.currentSegment) { |
|
343 currentMedia.currentSegment = new IriSP.Model.Annotation(false, project); |
|
344 currentMedia.currentSegment.setMedia(currentMedia.id); |
|
345 currentMedia.currentSegment.setBegin(0); |
|
346 currentMedia.currentSegment.setEnd(currentMedia.duration); |
|
347 currentMedia.currentSegment.thumbnail = currentMedia.thumbnail; |
|
348 currentMedia.currentSegment.title = "Segment sans titre"; |
|
349 currentMedia.currentSegment.description = "Extrait de « " + currentMedia.title + " »"; |
|
350 currentMedia.currentSegment.on("change-begin", function() { |
|
351 if (currentMedia && currentMedia.currentSegment === this) { |
|
352 currentMedia.setCurrentTime(this.begin); |
|
353 updateSliderAndTangles(); |
|
354 } |
|
355 }); |
|
356 currentMedia.currentSegment.on("change-end", function() { |
|
357 if (currentMedia && currentMedia.currentSegment === this) { |
|
358 currentMedia.setCurrentTime(this.end); |
|
359 updateSliderAndTangles(); |
|
360 } |
|
361 }); |
|
362 } |
|
363 updateSliderAndTangles(); |
279 } |
364 } |
280 currentvideo.show(); |
365 currentvideo.show(); |
281 $(".Ldt-Ctrl-Time-Total").text(currentMedia.duration.toString()); |
366 $(".Ldt-Ctrl-Time-Total").text(currentMedia.duration.toString()); |
|
367 $("#segment-title").val(currentMedia.currentSegment.title); |
|
368 $("#segment-description").text(currentMedia.currentSegment.description); |
|
369 // TODO: Do something with the tags ! |
282 onCurrentMediaTimeupdate(currentMedia.getCurrentTime()); |
370 onCurrentMediaTimeupdate(currentMedia.getCurrentTime()); |
283 onCurrentMediaPause(); |
371 onCurrentMediaPause(); |
284 } |
372 } |
285 |
373 |
286 function addMediaPlayer(media) { |
374 function addMediaPlayer(media) { |
390 |
478 |
391 media.on("timeupdate", function(_time) { |
479 media.on("timeupdate", function(_time) { |
392 if (media === currentMedia) { |
480 if (media === currentMedia) { |
393 onCurrentMediaTimeupdate(_time); |
481 onCurrentMediaTimeupdate(_time); |
394 } |
482 } |
395 }) |
483 }); |
396 |
484 |
397 } |
485 media.on("volumechange", function() { |
|
486 if (media === currentMedia) { |
|
487 ctrlVolumeUpdater(); |
|
488 } |
|
489 }) |
|
490 |
|
491 } |
|
492 |
|
493 /* Segment Form interaction */ |
|
494 |
|
495 $("#segment-title").on("keyup change input paste", function() { |
|
496 if (currentMedia && currentMedia.currentSegment) { |
|
497 currentMedia.currentSegment.title = $(this).val(); |
|
498 } |
|
499 }); |
|
500 $("#segment-description").on("keyup change input paste", function() { |
|
501 if (currentMedia && currentMedia.currentSegment) { |
|
502 currentMedia.currentSegment.title = $(this).val(); |
|
503 } |
|
504 }); |
|
505 $("#segment-form").submit(function() { |
|
506 mashup.addSegment(currentMedia.currentSegment); |
|
507 currentMedia.currentSegment = undefined; |
|
508 }) |
|
509 |
398 /* Click on media items */ |
510 /* Click on media items */ |
399 |
511 |
400 $(".col-left").on("click", ".item-video", function() { |
512 $(".col-left").on("click", ".item-video", function() { |
401 setMedia($(this).attr("data-media-id")); |
513 setMedia($(this).attr("data-media-id")); |
402 }); |
514 }); |
435 var currentItem = $(this).parents(".item-video"); |
547 var currentItem = $(this).parents(".item-video"); |
436 currentItem.insertAfter(currentItem.next()); |
548 currentItem.insertAfter(currentItem.next()); |
437 disableMoveItemVideo(); |
549 disableMoveItemVideo(); |
438 }); |
550 }); |
439 |
551 |
440 /* Tangle */ |
552 /* Tangles */ |
441 var activeTangle, |
553 var tangleMsPerPixel = 100, |
|
554 activeTangle, |
442 tangleStartX, |
555 tangleStartX, |
443 tangleStartVal; |
556 tangleStartVal, |
|
557 tangleHasMoved; |
|
558 |
444 $(".time-tangle").mousedown(function(evt) { |
559 $(".time-tangle").mousedown(function(evt) { |
445 activeTangle = $(this); |
560 activeTangle = $(this); |
446 activeTangle.addClass("active"); |
561 activeTangle.addClass("active"); |
447 tangleStartVal = +activeTangle.attr("data-milliseconds"); |
562 tangleStartVal = +activeTangle.attr("data-milliseconds"); |
448 tangleStartX = evt.pageX; |
563 tangleStartX = evt.pageX; |
|
564 tangleHasMoved = false; |
|
565 $(this).siblings(".time-tangle").addClass("deactivate"); |
449 return false; |
566 return false; |
450 }); |
567 }); |
451 $(document) |
568 $(document) |
452 .mousemove(function(evt) { |
569 .mousemove(function(evt) { |
453 if (activeTangle) { |
570 if (activeTangle) { |
454 var newval = new IriSP.Model.Time(100 * (evt.pageX - tangleStartX) + tangleStartVal); |
571 tangleHasMoved = true; |
455 activeTangle.text(newval.toString()); |
572 var newval = new IriSP.Model.Time(tangleMsPerPixel * (evt.pageX - tangleStartX) + tangleStartVal); |
456 activeTangle.attr("data-milliseconds",newval.milliseconds); |
|
457 activeTangle.trigger("valuechange", newval); |
573 activeTangle.trigger("valuechange", newval); |
458 return false; |
574 return false; |
459 } |
575 } |
460 }) |
576 }) |
461 .mouseup(function() { |
577 .mouseup(function() { |
462 if (activeTangle) { |
578 if (activeTangle) { |
463 activeTangle.removeClass("active"); |
579 $(".time-tangle").removeClass("active deactivate"); |
464 activeTangle = undefined; |
580 activeTangle = undefined; |
465 } |
581 } |
466 }) |
582 }); |
467 |
583 |
|
584 $(".tangle-start") |
|
585 .mouseup(function(evt) { |
|
586 if (!tangleHasMoved && currentMedia && currentMedia.currentSegment) { |
|
587 currentMedia.setCurrentTime(currentMedia.currentSegment.begin); |
|
588 } |
|
589 }) |
|
590 .on("valuechange", function(evt, val) { |
|
591 if (currentMedia && currentMedia.currentSegment) { |
|
592 currentMedia.currentSegment.setBegin(val); |
|
593 } |
|
594 }); |
|
595 $(".tangle-end") |
|
596 .mouseup(function(evt) { |
|
597 if (!tangleHasMoved && currentMedia && currentMedia.currentSegment) { |
|
598 currentMedia.setCurrentTime(currentMedia.currentSegment.end); |
|
599 } |
|
600 }) |
|
601 .on("valuechange", function(evt, val) { |
|
602 if (currentMedia && currentMedia.currentSegment) { |
|
603 currentMedia.currentSegment.setEnd(val); |
|
604 } |
|
605 }); |
|
606 $(".tangle-duration").on("valuechange", function(evt, val) { |
|
607 if (currentMedia && currentMedia.currentSegment) { |
|
608 currentMedia.currentSegment.setDuration(val); |
|
609 } |
|
610 }); |
468 } |
611 } |
469 |
612 |
470 $(function() { |
613 $(function() { |
471 var hashcut = new IriSP.Hashcut(); |
614 var hashcut = new IriSP.Hashcut(); |
472 }); |
615 }); |