32 resizeVideo(); |
32 resizeVideo(); |
33 |
33 |
34 var timeSlider = $("#progressBar"), |
34 var timeSlider = $("#progressBar"), |
35 slidersRange = 1000, |
35 slidersRange = 1000, |
36 wasPaused = true, |
36 wasPaused = true, |
37 lastVal = 0, |
37 lastVal = 0; |
38 isClicking = false; |
|
39 timeSlider.slider({ |
38 timeSlider.slider({ |
40 range: "min", |
39 range: "min", |
41 value: 0, |
40 value: 0, |
42 min: 0, |
41 min: 0, |
43 max: slidersRange, |
42 max: slidersRange, |
44 slide: function(event, ui) { |
43 slide: function(event, ui) { |
45 if (isClicking && Math.abs(lastVal - ui.value) > 10) { |
44 var t = currentSegment.begin + ( currentSegment.getDuration() * ui.value / slidersRange ); |
46 isClicking = false; |
45 currentMedia.setCurrentTime(t); |
47 } |
|
48 if (!isClicking && currentSegment && currentMedia) { |
|
49 var t = currentSegment.begin + ( currentSegment.getDuration() * ui.value / slidersRange ); |
|
50 currentMedia.setCurrentTime(t); |
|
51 } |
|
52 }, |
|
53 start: function(event, ui) { |
|
54 isClicking = true; |
|
55 lastVal = ui.value; |
|
56 }, |
|
57 stop: function(event, ui) { |
|
58 if (isClicking && currentMedia && currentSegment) { |
|
59 var t = currentMedia.getCurrentTime() - currentSegment.begin; |
|
60 timeSlider.slider("value", slidersRange * t / currentSegment.getDuration()); |
|
61 playOrPause(); |
|
62 } |
|
63 isClicking = false; |
|
64 } |
46 } |
65 }); |
47 }); |
66 |
48 |
67 $("#btnBck").click(function() { |
49 $("#btnBck").click(function() { |
68 var newn = currentIndex ? ( currentIndex - 1 ) : ( seqCount - 1 ); |
50 var newn = currentIndex ? ( currentIndex - 1 ) : ( seqCount - 1 ); |
141 }); |
123 }); |
142 |
124 |
143 $(window).on("resize", resizeTagsDrag); |
125 $(window).on("resize", resizeTagsDrag); |
144 resizeTagsDrag(); |
126 resizeTagsDrag(); |
145 |
127 |
146 var taginput = $("#form_tag input[type=text]"); |
128 var taginput = $("#form_tag input[type=text]"), |
|
129 replacerx; |
147 taginput.autocomplete({ |
130 taginput.autocomplete({ |
148 source: function(params, response) { |
131 source: function(params, response) { |
149 var rx = new RegExp(params.term,"gi"); |
132 var charsub = [ '[aáàâä]', '[cç]', '[eéèêë]', '[iíìîï]', '[oóòôö]' ], |
|
133 term = params.term.replace(/([\\\*\+\?\|\{\[\}\]\(\)\^\$\.\#\/])/gm, '\\$1'); |
|
134 _(charsub).each(function(chars) { |
|
135 var tmprx = new RegExp(chars,"gim"); |
|
136 term = term.replace(tmprx, chars); |
|
137 }); |
|
138 var searchrx = new RegExp("(^|\\s)" + term, "i"); |
|
139 replacerx = new RegExp("(^|\\s)(" + term + ")", "gi"); |
150 response( |
140 response( |
151 _(globalTags) |
141 _(globalTags) |
152 .chain() |
142 .chain() |
153 .keys() |
143 .keys() |
154 .filter(function(tag) { |
144 .filter(function(tag) { |
155 return rx.test(tag) |
145 return searchrx.test(tag) |
156 }) |
146 }) |
157 .shuffle() |
147 .sortBy(_.identity) |
158 .first(5) |
|
159 .value() |
148 .value() |
160 ); |
149 ); |
161 } |
150 } |
162 }); |
151 }).data("autocomplete")._renderItem = function(ul, item) { |
|
152 return $( "<li>" ) |
|
153 .data( "item.autocomplete", item ) |
|
154 .append( "<a>" + item.label.replace(replacerx, '$1<b>$2</b>') + "</a>" ) |
|
155 .appendTo( ul ); |
|
156 }; |
163 taginput.on("keyup input paste", function() { |
157 taginput.on("keyup input paste", function() { |
164 taginput.val(taginput.val().toUpperCase()); |
158 taginput.val(taginput.val().toUpperCase()); |
165 }); |
159 }); |
166 $("#form_tag").on("submit", function() { |
160 $("#form_tag").on("submit", function() { |
167 var _tagvalue = taginput.val().toUpperCase(); |
161 var _tagvalue = taginput.val().toUpperCase(); |
|
162 taginput.val(""); |
168 if (_tagvalue && currentSegment) { |
163 if (_tagvalue && currentSegment) { |
169 /* Création d'une liste d'annotations contenant une annotation afin de l'envoyer au serveur */ |
164 /* Création d'une liste d'annotations contenant une annotation afin de l'envoyer au serveur */ |
170 var _exportedAnnotations = new IriSP.Model.List(directory), |
165 var _exportedAnnotations = new IriSP.Model.List(directory), |
171 /* Création d'un objet source utilisant un sérialiseur spécifique pour l'export */ |
166 /* Création d'un objet source utilisant un sérialiseur spécifique pour l'export */ |
172 _export = directory.newLocalSource({ |
167 _export = directory.newLocalSource({ |
189 _annotation.setBegin(currentSegment.begin); |
184 _annotation.setBegin(currentSegment.begin); |
190 _annotation.setEnd(currentSegment.end); |
185 _annotation.setEnd(currentSegment.end); |
191 |
186 |
192 _annotation.setAnnotationType(_annotationType.id); |
187 _annotation.setAnnotationType(_annotationType.id); |
193 |
188 |
194 _annotation.title = _tagvalue; |
189 _annotation.title = currentSegment.title; |
195 _annotation.created = new Date(); /* Date de création de l'annotation */ |
190 _annotation.created = new Date(); /* Date de création de l'annotation */ |
196 _annotation.description = _tagvalue; |
191 _annotation.description = _tagvalue; |
197 |
192 |
198 _annotation.setTags([_tag.id]); /*Liste des ids de tags */ |
193 _annotation.setTags([_tag.id]); /*Liste des ids de tags */ |
199 |
194 |
200 /* Les données créateur/date de création sont envoyées non pas dans l'annotation, mais dans le projet */ |
195 _annotation.creator = "theend"; |
201 _export.creator = "theend"; |
196 _annotation.created = new Date(); |
202 _export.created = new Date(); |
|
203 /* Ajout de l'annotation à la liste à exporter */ |
197 /* Ajout de l'annotation à la liste à exporter */ |
204 _exportedAnnotations.push(_annotation); |
198 _exportedAnnotations.push(_annotation); |
205 /* Ajout de la liste à exporter à l'objet Source */ |
199 /* Ajout de la liste à exporter à l'objet Source */ |
206 _export.addList("annotation",_exportedAnnotations); |
200 _export.addList("annotation",_exportedAnnotations); |
207 |
201 |
290 } |
284 } |
291 timeSlider.slider("value",0); |
285 timeSlider.slider("value",0); |
292 currentMedia.setCurrentTime(currentSegment.begin); |
286 currentMedia.setCurrentTime(currentSegment.begin); |
293 if (!currentMedia.loaded) { |
287 if (!currentMedia.loaded) { |
294 $(".video-wait").show(); |
288 $(".video-wait").show(); |
295 $("#btnPlayPause, .video-wait, #progressBar .ui-slider-handle").removeClass("pause"); |
289 $("#btnPlayPause, .video-wait").removeClass("pause"); |
296 } |
290 } |
297 currentMedia.play(); |
291 currentMedia.play(); |
298 } |
292 } |
299 |
293 |
300 function showCurrentTags() { |
294 function showCurrentTags() { |
301 var vals = _(currentSegment.__tags).values(), |
295 var vals = _(currentSegment.__tags).values(), |
302 max = Math.max.apply(Math, vals), |
296 max = Math.max.apply(Math, vals), |
303 min = Math.min(max - 1, Math.min.apply(Math, vals)), |
297 min = Math.min(max - 1, Math.min.apply(Math, vals)), |
304 b = 128 / (max - min); |
298 b = 160 / (max - min); |
305 var html = _(currentSegment.__tags) |
299 var html = _(currentSegment.__tags) |
306 .chain() |
300 .chain() |
307 .map(function(v, k) { |
301 .map(function(v, k) { |
308 var c = Math.floor( 127 + (v - min) * b ); |
302 var c = Math.floor( 95 + (v - min) * b ); |
309 return '<li><a href="' |
303 return '<li><a href="' |
310 + IriSP.endpoints.tag_page.replace("__TAG__",encodeURIComponent(k)) |
304 + IriSP.endpoints.tag_page.replace("__TAG__",encodeURIComponent(k)) |
311 + '" style="color: rgb(' |
305 + '" style="color: rgb(' |
312 + [c,c,c].join(",") |
306 + [c,c,c].join(",") |
313 + ')">' |
307 + ')">' |
332 if (typeof IriSP.video_url_transform === "function") { |
326 if (typeof IriSP.video_url_transform === "function") { |
333 videourl = IriSP.video_url_transform(media.video); |
327 videourl = IriSP.video_url_transform(media.video); |
334 } |
328 } |
335 var videoid = "video_" + media.id, |
329 var videoid = "video_" + media.id, |
336 videoEl = $('<video>'), |
330 videoEl = $('<video>'), |
337 seekCache = undefined, |
|
338 mp4_file = videourl.replace(/\.webm$/i,'.mp4'), |
331 mp4_file = videourl.replace(/\.webm$/i,'.mp4'), |
339 webm_file = videourl.replace(/\.mp4$/i,'.webm'), |
332 webm_file = videourl.replace(/\.mp4$/i,'.webm'), |
340 mp4_src = $('<source>'), |
333 mediaEl = videoEl[0], |
341 webm_src = $('<source>'); |
334 can_play_mp4 = !!mediaEl.canPlayType('video/mp4'), |
342 |
335 can_play_webm = !!mediaEl.canPlayType('video/webm'); |
343 mp4_src.attr({ |
336 |
344 src: mp4_file, |
|
345 type: "video/mp4" |
|
346 }) |
|
347 webm_src.attr({ |
|
348 src: webm_file, |
|
349 type: "video/webm" |
|
350 }); |
|
351 |
|
352 videoEl.attr({ |
337 videoEl.attr({ |
353 id : videoid |
338 id : videoid |
354 }).css({ |
339 }).css({ |
355 position : "absolute", |
340 position : "absolute", |
356 left: 0, |
341 left: 0, |
357 top: 0, |
342 top: 0, |
358 width : "100%", |
343 width : "100%", |
359 height : "100%" |
344 height : "100%" |
360 }); |
345 }); |
361 videoEl.append(mp4_src).append(webm_src); |
346 |
|
347 if (can_play_mp4 && can_play_webm) { |
|
348 var mp4_src = $('<source>'), |
|
349 webm_src = $('<source>'); |
|
350 mp4_src.attr({ |
|
351 src: mp4_file, |
|
352 type: "video/mp4" |
|
353 }); |
|
354 webm_src.attr({ |
|
355 src: webm_file, |
|
356 type: "video/webm" |
|
357 }); |
|
358 |
|
359 videoEl.append(mp4_src).append(webm_src); |
|
360 } else { |
|
361 videoEl.attr("src", can_play_mp4 ? mp4_file : webm_file); |
|
362 } |
|
363 |
362 $("#video_sequence").append(videoEl); |
364 $("#video_sequence").append(videoEl); |
363 var mediaEl = videoEl[0]; |
|
364 |
365 |
365 media.show = function() { |
366 media.show = function() { |
366 videoEl.show(); |
367 videoEl.show(); |
367 } |
368 } |
368 media.hide = function() { |
369 media.hide = function() { |
449 |
450 |
450 // Binding UI Events and Mashup Playing to Media |
451 // Binding UI Events and Mashup Playing to Media |
451 |
452 |
452 media.on("play", function() { |
453 media.on("play", function() { |
453 if (media === currentMedia) { |
454 if (media === currentMedia) { |
454 $("#btnPlayPause, .video-wait, #progressBar .ui-slider-handle").addClass("pause"); |
455 $("#btnPlayPause, .video-wait").addClass("pause"); |
455 } |
456 } |
456 }); |
457 }); |
457 |
458 |
458 media.on("pause", function() { |
459 media.on("pause", function() { |
459 if (media === currentMedia) { |
460 if (media === currentMedia) { |
460 $("#btnPlayPause, .video-wait, #progressBar .ui-slider-handle").removeClass("pause"); |
461 $("#btnPlayPause, .video-wait").removeClass("pause"); |
461 } |
462 } |
462 }); |
463 }); |
463 |
464 |
464 media.on("timeupdate", function(_time) { |
465 media.on("timeupdate", function(_time) { |
465 if (media === currentMedia) { |
466 if (media === currentMedia) { |
469 t = Math.max(0, _time - currentSegment.begin); |
470 t = Math.max(0, _time - currentSegment.begin); |
470 } else { |
471 } else { |
471 media.setCurrentTime(currentSegment.begin); |
472 media.setCurrentTime(currentSegment.begin); |
472 } |
473 } |
473 $("#current").text(new IriSP.Model.Time(t).toString()); |
474 $("#current").text(new IriSP.Model.Time(t).toString()); |
474 if (!isClicking) { |
475 timeSlider.slider("value", slidersRange * t / currentSegment.getDuration()); |
475 timeSlider.slider("value", slidersRange * t / currentSegment.getDuration()); |
|
476 } |
|
477 } else { |
476 } else { |
478 media.pause(); |
477 media.pause(); |
479 goToPart((currentIndex + 1) % seqCount) |
478 goToPart((currentIndex + 1) % seqCount) |
480 } |
479 } |
481 } |
480 } |