|
50
|
1 |
IriSP.contentplayer = function(opts) { |
|
|
2 |
var directory = new IriSP.Model.Directory(), |
|
|
3 |
project = directory.remoteSource({ |
|
|
4 |
url: opts.project_url, |
|
|
5 |
serializer: IriSP.serializers.ldt |
|
|
6 |
}), |
|
|
7 |
apidirectory = new IriSP.Model.Directory(), |
|
|
8 |
currentIndex = 0, |
|
|
9 |
currentSegment, |
|
|
10 |
currentMedia, |
|
|
11 |
globalTags = {}, |
|
|
12 |
seqCount; |
|
|
13 |
|
|
|
14 |
var ratio = 2.37; |
|
|
15 |
|
|
|
16 |
function resizeVideo() { |
|
|
17 |
var currentwidth = $(window).width(), |
|
|
18 |
maxheight = $(window).height() - 220, |
|
|
19 |
height = Math.min(maxheight, currentwidth / ratio), |
|
|
20 |
width = ratio * height; |
|
|
21 |
$("#video_sequence").css({ |
|
|
22 |
width: Math.floor(width), |
|
|
23 |
height: Math.floor(height) |
|
|
24 |
}); |
|
|
25 |
} |
|
|
26 |
|
|
|
27 |
$(window).on("resize", resizeVideo); |
|
|
28 |
resizeVideo(); |
|
|
29 |
|
|
|
30 |
var timeSlider = $("#progressBar"), |
|
|
31 |
slidersRange = 1000, |
|
|
32 |
wasPaused = true, |
|
64
|
33 |
lastVal = 0; |
|
50
|
34 |
timeSlider.slider({ |
|
|
35 |
range: "min", |
|
|
36 |
value: 0, |
|
|
37 |
min: 0, |
|
|
38 |
max: slidersRange, |
|
|
39 |
slide: function(event, ui) { |
|
64
|
40 |
currentMedia.setCurrentTime(currentMedia.duration * ui.value / slidersRange); |
|
50
|
41 |
} |
|
|
42 |
}); |
|
|
43 |
|
|
|
44 |
function playOrPause() { |
|
|
45 |
if (currentMedia) { |
|
|
46 |
if (currentMedia.paused) { |
|
|
47 |
currentMedia.play(); |
|
|
48 |
} else { |
|
|
49 |
currentMedia.pause(); |
|
|
50 |
} |
|
|
51 |
} |
|
|
52 |
} |
|
|
53 |
|
|
|
54 |
$(".video-wait, #btnPlayPause").click(function() { |
|
|
55 |
playOrPause(); |
|
|
56 |
return false; |
|
|
57 |
}); |
|
|
58 |
|
|
|
59 |
var segmentdragout = $("#title_sequence"), |
|
|
60 |
segmentdragin = segmentdragout.find("ul") |
|
|
61 |
segmentdragging = false; |
|
|
62 |
|
|
|
63 |
function resizeSegmentDrag() { |
|
|
64 |
var segmentdelta = segmentdragout.width() - segmentdragin.width(); |
|
|
65 |
segmentdragin.draggable("option","containment",segmentdelta < 0 ? [ segmentdelta - 20, 0, 20, 0 ] : "parent") |
|
|
66 |
} |
|
|
67 |
|
|
|
68 |
segmentdragin.draggable({ |
|
|
69 |
axis: "x", |
|
|
70 |
start: function() { |
|
|
71 |
segmentdragging = true; |
|
|
72 |
}, |
|
|
73 |
stop: function() { |
|
|
74 |
segmentdragging = false; |
|
|
75 |
} |
|
|
76 |
}); |
|
|
77 |
|
|
|
78 |
$(window).on("resize", resizeSegmentDrag); |
|
|
79 |
resizeSegmentDrag(); |
|
|
80 |
|
|
|
81 |
segmentdragin.on("mouseup", "li", function() { |
|
|
82 |
if (!segmentdragging) { |
|
|
83 |
var s = project.getElement($(this).attr("data-segment-id")); |
|
|
84 |
if (s) { |
|
|
85 |
currentMedia.setCurrentTime(s.begin); |
|
|
86 |
} |
|
|
87 |
} |
|
|
88 |
}).click(function() { |
|
|
89 |
return false; |
|
|
90 |
}); |
|
|
91 |
|
|
|
92 |
var tagsdragout = $("#tag_sequence"), |
|
|
93 |
tagsdragin = tagsdragout.find("ul") |
|
|
94 |
tagsdragging = false; |
|
|
95 |
|
|
|
96 |
function resizeTagsDrag() { |
|
|
97 |
var tagsdelta = tagsdragout.width() - tagsdragin.width(); |
|
|
98 |
tagsdragin.draggable("option","containment",tagsdelta < 0 ? [ tagsdelta - 20, 0, 20, 0 ] : "parent"); |
|
|
99 |
tagsdragin.css("left",Math.floor(tagsdelta/2)); |
|
|
100 |
} |
|
|
101 |
|
|
|
102 |
tagsdragin.draggable({ |
|
|
103 |
axis: "x", |
|
|
104 |
start: function() { |
|
|
105 |
tagsdragging = true; |
|
|
106 |
}, |
|
|
107 |
stop: function() { |
|
|
108 |
tagsdragging = false; |
|
|
109 |
} |
|
|
110 |
}); |
|
|
111 |
|
|
|
112 |
$(window).on("resize", resizeTagsDrag); |
|
|
113 |
resizeTagsDrag(); |
|
|
114 |
|
|
64
|
115 |
var taginput = $("#form_tag input[type=text]"), |
|
|
116 |
replacerx; |
|
50
|
117 |
taginput.autocomplete({ |
|
|
118 |
source: function(params, response) { |
|
64
|
119 |
var charsub = [ '[aáà âä]', '[cç]', '[eéèêë]', '[iÃìîï]', '[oóòôö]' ], |
|
|
120 |
term = params.term.replace(/([\\\*\+\?\|\{\[\}\]\(\)\^\$\.\#\/])/gm, '\\$1'); |
|
|
121 |
_(charsub).each(function(chars) { |
|
|
122 |
var tmprx = new RegExp(chars,"gim"); |
|
|
123 |
term = term.replace(tmprx, chars); |
|
|
124 |
}); |
|
|
125 |
var searchrx = new RegExp("(^|\\s)" + term, "i"); |
|
|
126 |
replacerx = new RegExp("(^|\\s)(" + term + ")", "gi"); |
|
50
|
127 |
response( |
|
|
128 |
_(globalTags) |
|
|
129 |
.chain() |
|
|
130 |
.keys() |
|
|
131 |
.filter(function(tag) { |
|
64
|
132 |
return searchrx.test(tag) |
|
50
|
133 |
}) |
|
64
|
134 |
.sortBy(_.identity) |
|
50
|
135 |
.value() |
|
|
136 |
); |
|
|
137 |
} |
|
64
|
138 |
}).data("autocomplete")._renderItem = function(ul, item) { |
|
|
139 |
return $( "<li>" ) |
|
|
140 |
.data( "item.autocomplete", item ) |
|
|
141 |
.append( "<a>" + item.label.replace(replacerx, '$1<b>$2</b>') + "</a>" ) |
|
|
142 |
.appendTo( ul ); |
|
|
143 |
}; |
|
50
|
144 |
taginput.on("keyup input paste", function() { |
|
|
145 |
taginput.val(taginput.val().toUpperCase()); |
|
|
146 |
}); |
|
|
147 |
$("#form_tag").on("submit", function() { |
|
|
148 |
var _tagvalue = taginput.val().toUpperCase(); |
|
64
|
149 |
taginput.val(""); |
|
50
|
150 |
if (_tagvalue && currentSegment) { |
|
|
151 |
/* Création d'une liste d'annotations contenant une annotation afin de l'envoyer au serveur */ |
|
|
152 |
var _exportedAnnotations = new IriSP.Model.List(directory), |
|
|
153 |
/* Création d'un objet source utilisant un sérialiseur spécifique pour l'export */ |
|
|
154 |
_export = directory.newLocalSource({ |
|
|
155 |
serializer: IriSP.serializers.ldt_annotate |
|
|
156 |
}), |
|
|
157 |
/* Création d'une annotation dans cette source avec un ID généré à la volée (param. false) */ |
|
|
158 |
_annotation = new IriSP.Model.Annotation(false, _export), |
|
|
159 |
/* Si le Type d'Annotation n'existe pas, il est créé à la volée */ |
|
|
160 |
_annotationType = new IriSP.Model.AnnotationType(false, _export), |
|
|
161 |
/* L'objet Tag qui sera envoyé */ |
|
|
162 |
_tag = new IriSP.Model.Tag(false, _export); |
|
|
163 |
/* L'objet Tag doit avoir pour titre le texte du tag envoyé */ |
|
|
164 |
_tag.title = _tagvalue; |
|
|
165 |
/* Si nous avons dû générer un ID d'annotationType à la volée... */ |
|
|
166 |
_annotationType.dont_send_id = true; |
|
|
167 |
/* Il faut inclure le titre dans le type d'annotation */ |
|
|
168 |
_annotationType.title = "Contribution"; |
|
|
169 |
|
|
|
170 |
_annotation.setMedia(currentSegment.getMedia().id); |
|
|
171 |
_annotation.setBegin(currentSegment.begin); |
|
|
172 |
_annotation.setEnd(currentSegment.end); |
|
|
173 |
|
|
|
174 |
_annotation.setAnnotationType(_annotationType.id); |
|
|
175 |
|
|
64
|
176 |
_annotation.title = currentSegment.title; |
|
50
|
177 |
_annotation.created = new Date(); /* Date de création de l'annotation */ |
|
|
178 |
_annotation.description = _tagvalue; |
|
|
179 |
|
|
|
180 |
_annotation.setTags([_tag.id]); /*Liste des ids de tags */ |
|
|
181 |
|
|
64
|
182 |
_annotation.creator = "theend"; |
|
|
183 |
_annotation.created = new Date(); |
|
50
|
184 |
/* Ajout de l'annotation à la liste à exporter */ |
|
|
185 |
_exportedAnnotations.push(_annotation); |
|
|
186 |
/* Ajout de la liste à exporter à l'objet Source */ |
|
|
187 |
_export.addList("annotation",_exportedAnnotations); |
|
|
188 |
|
|
|
189 |
var segmentAtPost = currentSegment; |
|
|
190 |
|
|
|
191 |
IriSP.jQuery.ajax({ |
|
|
192 |
url: IriSP.endpoints.post_annotation, |
|
|
193 |
type: "POST", |
|
|
194 |
contentType: 'application/json', |
|
|
195 |
data: _export.serialize(), /* L'objet Source est sérialisé */ |
|
|
196 |
success: function(_data) { |
|
|
197 |
var n = 1 + (segmentAtPost.__tags[_tagvalue] || 0) |
|
|
198 |
segmentAtPost.__tags[_tagvalue] = n; |
|
|
199 |
showCurrentTags(); |
|
|
200 |
}, |
|
|
201 |
error: function(_xhr, _error, _thrown) { |
|
|
202 |
console.log("Error when sending annotation", _thrown); |
|
|
203 |
} |
|
|
204 |
}); |
|
|
205 |
} |
|
|
206 |
return false; |
|
|
207 |
}); |
|
|
208 |
|
|
|
209 |
project.onLoad(function() { |
|
|
210 |
|
|
|
211 |
currentMedia = project.currentMedia; |
|
|
212 |
|
|
|
213 |
addMedia(currentMedia); |
|
|
214 |
|
|
|
215 |
$("#duration").text(currentMedia.duration.toString()); |
|
|
216 |
$("h1").text(currentMedia.title); //TODO: Remove when on platform |
|
|
217 |
var segmentsHtml = ""; |
|
|
218 |
|
|
|
219 |
project.getAnnotations().forEach(function(s) { |
|
|
220 |
segmentsHtml += '<li data-segment-id="' + s.id + '"><a href="#">' + s.title + ' </a> </li>'; |
|
|
221 |
var url = IriSP.endpoints.annotations_by_timecode |
|
|
222 |
.replace('__CONTENT_ID__', s.getMedia().id) |
|
|
223 |
.replace('__BEGIN__', s.begin.valueOf()) |
|
|
224 |
.replace('__END__', s.end.valueOf()); |
|
|
225 |
var proj = apidirectory.remoteSource({ |
|
|
226 |
url: url, |
|
|
227 |
serializer: IriSP.serializers.ldt |
|
|
228 |
}); |
|
|
229 |
proj.__segment = s; |
|
|
230 |
proj.onLoad(function() { |
|
|
231 |
proj.__segment.__tags = {}; |
|
|
232 |
proj.getAnnotations().forEach(function(a) { |
|
|
233 |
var tags = a.getTagTexts(); |
|
|
234 |
_(tags).each(function(t) { |
|
|
235 |
var upt = t.toUpperCase(), |
|
|
236 |
nl = 1 + (proj.__segment.__tags[upt] || 0), |
|
|
237 |
ng = 1 + (globalTags[upt] || 0); |
|
|
238 |
proj.__segment.__tags[upt] = nl; |
|
|
239 |
globalTags[upt] = ng; |
|
|
240 |
}); |
|
|
241 |
if (proj.__segment === currentSegment) { |
|
|
242 |
showCurrentTags(); |
|
|
243 |
} |
|
|
244 |
}); |
|
|
245 |
}); |
|
|
246 |
s.on("enter", function() { |
|
|
247 |
currentSegment = s; |
|
|
248 |
showCurrentTags(); |
|
|
249 |
$("#title_sequence li").removeClass("here"); |
|
|
250 |
$("#title_sequence li[data-segment-id='" + s.id + "']").addClass("here"); |
|
|
251 |
}); |
|
|
252 |
}); |
|
|
253 |
|
|
|
254 |
segmentdragin.html(segmentsHtml); |
|
|
255 |
resizeSegmentDrag(); |
|
|
256 |
|
|
|
257 |
currentMedia.play(); |
|
|
258 |
}); |
|
|
259 |
|
|
|
260 |
function showCurrentTags() { |
|
|
261 |
var vals = _(currentSegment.__tags).values(), |
|
|
262 |
max = Math.max.apply(Math, vals), |
|
|
263 |
min = Math.min(max - 1, Math.min.apply(Math, vals)), |
|
|
264 |
b = 160 / (max - min); |
|
|
265 |
var html = _(currentSegment.__tags) |
|
|
266 |
.chain() |
|
|
267 |
.map(function(v, k) { |
|
|
268 |
var c = Math.floor( 95 + (v - min) * b ); |
|
|
269 |
return '<li><a href="' |
|
|
270 |
+ IriSP.endpoints.tag_page.replace("__TAG__",encodeURIComponent(k)) |
|
|
271 |
+ '" style="color: rgb(' |
|
|
272 |
+ [c,c,c].join(",") |
|
|
273 |
+ ')">' |
|
|
274 |
+ k |
|
|
275 |
+ ' </a> </li>' |
|
|
276 |
}) |
|
|
277 |
.shuffle() |
|
|
278 |
.value() |
|
|
279 |
.join(""); |
|
|
280 |
tagsdragin.html(html); |
|
|
281 |
resizeTagsDrag(); |
|
|
282 |
} |
|
|
283 |
|
|
|
284 |
function addMedia(media) { |
|
|
285 |
if (media.has_player) { |
|
|
286 |
return; |
|
|
287 |
} |
|
|
288 |
media.has_player = true; |
|
|
289 |
media.loaded = false; |
|
|
290 |
media.paused = true; |
|
|
291 |
var videourl = media.video; |
|
|
292 |
if (typeof IriSP.video_url_transform === "function") { |
|
|
293 |
videourl = IriSP.video_url_transform(media.video); |
|
|
294 |
} |
|
|
295 |
var videoid = "video_" + media.id, |
|
|
296 |
videoEl = $('<video>'), |
|
|
297 |
mp4_file = videourl.replace(/\.webm$/i,'.mp4'), |
|
|
298 |
webm_file = videourl.replace(/\.mp4$/i,'.webm'), |
|
64
|
299 |
mediaEl = videoEl[0], |
|
|
300 |
can_play_mp4 = !!mediaEl.canPlayType('video/mp4'), |
|
|
301 |
can_play_webm = !!mediaEl.canPlayType('video/webm'); |
|
|
302 |
|
|
50
|
303 |
videoEl.attr({ |
|
|
304 |
id : videoid |
|
|
305 |
}).css({ |
|
|
306 |
position : "absolute", |
|
|
307 |
left: 0, |
|
|
308 |
top: 0, |
|
|
309 |
width : "100%", |
|
|
310 |
height : "100%" |
|
|
311 |
}); |
|
64
|
312 |
|
|
|
313 |
if (can_play_mp4 && can_play_webm) { |
|
|
314 |
var mp4_src = $('<source>'), |
|
|
315 |
webm_src = $('<source>'); |
|
|
316 |
mp4_src.attr({ |
|
|
317 |
src: mp4_file, |
|
|
318 |
type: "video/mp4" |
|
|
319 |
}); |
|
|
320 |
webm_src.attr({ |
|
|
321 |
src: webm_file, |
|
|
322 |
type: "video/webm" |
|
|
323 |
}); |
|
|
324 |
|
|
|
325 |
videoEl.append(mp4_src).append(webm_src); |
|
|
326 |
} else { |
|
|
327 |
videoEl.attr("src", can_play_mp4 ? mp4_file : webm_file); |
|
|
328 |
} |
|
|
329 |
|
|
50
|
330 |
$("#video_sequence").append(videoEl); |
|
|
331 |
|
|
|
332 |
media.show = function() { |
|
|
333 |
videoEl.show(); |
|
|
334 |
} |
|
|
335 |
media.hide = function() { |
|
|
336 |
videoEl.hide(); |
|
|
337 |
} |
|
|
338 |
|
|
|
339 |
// Binding functions to Media Element Functions |
|
|
340 |
|
|
|
341 |
media.on("setcurrenttime", function(_milliseconds) { |
|
|
342 |
try { |
|
|
343 |
mediaEl.currentTime = (_milliseconds / 1000); |
|
|
344 |
} |
|
|
345 |
catch (err) {} |
|
|
346 |
}); |
|
|
347 |
|
|
|
348 |
media.on("setvolume", function(_vol) { |
|
|
349 |
try { |
|
|
350 |
media.volume = _vol; |
|
|
351 |
mediaEl.volume = _vol; |
|
|
352 |
} |
|
|
353 |
catch (err) {} |
|
|
354 |
}); |
|
|
355 |
|
|
|
356 |
media.on("setmuted", function(_muted) { |
|
|
357 |
try { |
|
|
358 |
media.muted = _muted; |
|
|
359 |
mediaEl.muted = _muted; |
|
|
360 |
} |
|
|
361 |
catch (err) {} |
|
|
362 |
}); |
|
|
363 |
|
|
|
364 |
media.on("setplay", function() { |
|
|
365 |
try { |
|
|
366 |
mediaEl.play(); |
|
|
367 |
} |
|
|
368 |
catch (err) {} |
|
|
369 |
}); |
|
|
370 |
|
|
|
371 |
media.on("setpause", function() { |
|
|
372 |
try { |
|
|
373 |
mediaEl.pause(); |
|
|
374 |
} |
|
|
375 |
catch (err) {} |
|
|
376 |
}); |
|
|
377 |
|
|
|
378 |
// Binding DOM events to media |
|
|
379 |
|
|
|
380 |
function getVolume() { |
|
|
381 |
media.muted = mediaEl.muted; |
|
|
382 |
media.volume = mediaEl.volume; |
|
|
383 |
} |
|
|
384 |
|
|
|
385 |
videoEl.on("loadedmetadata", function() { |
|
|
386 |
getVolume(); |
|
|
387 |
media.loaded = true; |
|
|
388 |
media.trigger("loadedmetadata"); |
|
|
389 |
media.trigger("volumechange"); |
|
|
390 |
}) |
|
|
391 |
|
|
|
392 |
videoEl.on("timeupdate", function() { |
|
|
393 |
media.trigger("timeupdate", new IriSP.Model.Time(1000*mediaEl.currentTime)); |
|
|
394 |
}); |
|
|
395 |
|
|
|
396 |
videoEl.on("volumechange", function() { |
|
|
397 |
getVolume(); |
|
|
398 |
media.trigger("volumechange"); |
|
|
399 |
}) |
|
|
400 |
|
|
|
401 |
videoEl.on("play", function() { |
|
|
402 |
media.trigger("play"); |
|
|
403 |
}); |
|
|
404 |
|
|
|
405 |
videoEl.on("pause", function() { |
|
|
406 |
media.trigger("pause"); |
|
|
407 |
}); |
|
|
408 |
|
|
|
409 |
videoEl.on("seeking", function() { |
|
|
410 |
media.trigger("seeking"); |
|
|
411 |
}); |
|
|
412 |
|
|
|
413 |
videoEl.on("seeked", function() { |
|
|
414 |
media.trigger("seeked"); |
|
|
415 |
}); |
|
|
416 |
|
|
|
417 |
// Binding UI Events and Mashup Playing to Media |
|
|
418 |
|
|
|
419 |
media.on("play", function() { |
|
64
|
420 |
$("#btnPlayPause, .video-wait").addClass("pause"); |
|
50
|
421 |
}); |
|
|
422 |
|
|
|
423 |
media.on("pause", function() { |
|
64
|
424 |
$("#btnPlayPause, .video-wait").removeClass("pause"); |
|
50
|
425 |
}); |
|
|
426 |
|
|
|
427 |
media.on("timeupdate", function(_time) { |
|
|
428 |
$("#current").text(_time.toString()); |
|
64
|
429 |
timeSlider.slider("value", slidersRange * _time / media.duration); |
|
50
|
430 |
}); |
|
64
|
431 |
|
|
50
|
432 |
} |
|
|
433 |
|
|
|
434 |
} |