-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-browse.php
557 lines (471 loc) · 21.6 KB
/
test-browse.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
<?php
/* A quick mockup used during the paired research session on Sep. 27, 2012 */
session_start();
if(!isset($_SESSION["username"])){
header("location:index.php");
}
$video_id = $_GET["vid"];
//$user_id = $_GET["uid"];
if (isset($_GET["tid"]))
$task_id = $_GET["tid"];
else
$task_id = 0;
if (isset($_GET["tm"]))
$tm = $_GET["tm"];
else
$tm = -1;
//if (isset($_GET["iid"]))
// $interface_id = $_GET["iid"];
//else
$interface_id = 3;
include "conn.php";
$result = $mysqli->query("SELECT * FROM videos WHERE id='$video_id'");
if ($result->num_rows != 1)
echo "query error";
$video = $result->fetch_assoc();
$duration = $video['duration'];
$video_filename = $video['filename'];
$string = file_get_contents("video/$video_filename.info.json");
$json = json_decode($string, true);
//$result = $mysqli->query("SELECT * FROM labels WHERE video_id='$video_id' AND user_id='$user_id' ORDER BY tm ASC");
$result = $mysqli->query("SELECT * FROM labels WHERE video_id='$video_id' ORDER BY tm ASC");
$labels = array();
while ($row = $result->fetch_assoc()) {
$labels[] = $row;
}
$result->free();
$mysqli->close();
?>
<?php
include('header.php');
?>
<h3><a href="javascript:history.go(-1)"><< Back to list</a></h3>
<!--<h2><?=$video['title'];?></h2>-->
<!--<div id="description"><?=$json['description'];?></div>-->
<?php if ($interface_id == 1) { ?>
<div id="mediaplayer" class="row">loading video...</div>
<div class="row">
<div class="span12">
<div id="timeline">
<div id="control-left">
<a class="btn btn-small" href="#" id="play-button"><i class="icon-play"></i></a>
<span id="elapsed" class="time-display">0:00</span>
</div>
<div id="control-center">
<!--<div id="playhead"></div>-->
<!--<div id="seekhead"></div>-->
<div id="timeline-bottom"></div>
</div>
<div id="control-right">
<span id="duration" class="time-display">0:00</span>
</div>
</div>
</div>
</div>
<?php } elseif ($interface_id == 2) { ?>
<div id="mediaplayer" class="row">loading video...</div>
<?php } elseif ($interface_id == 3) { ?>
<ul id="html_tutorial">
</ul>
<!--<div id="mediaplayer" class="row" style="display:none"></div>-->
<?php } elseif ($interface_id == 4) { ?>
<div id="mediaplayer" class="row">loading video...</div>
<div id="tabs" class="row">
<ul>
<li><a href="#tabs-1">Before and After</a></li>
<li><a href="#tabs-4">Slide Show</a></li>
<li><a href="#tabs-2">Works in Progress</a></li>
<li><a href="#tabs-3">Step by Step</a></li>
</ul>
<div id="tabs-1"></div>
<div id="tabs-4"></div>
<div id="tabs-2"></div>
<div id="tabs-3"></div>
</div>
<?php } ?>
</div><!--container-->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="js/libs/jquery-1.7.2.min.js"><\/script>')</script>
<script src="js/libs/bootstrap/bootstrap.min.js"></script>
<script type="text/javascript" src="js/libs/jquery-ui-1.8.22.custom.min.js"></script>
<script type="text/javascript" src="js/libs/jwplayer/jwplayer.js"></script>
<script type="text/javascript" src="js/libs/jcarousel/jquery.jcarousel.min.js"></script>
<script type="text/javascript" src="js/libs/imagesloaded/jquery.imagesloaded.min.js"></script>
<script src="js/libs/log4javascript.js"></script>
<script src="js/script.js"></script>
<script type="text/javascript">
function jump(time) {
var elapsed = jwplayer().getPosition();
jwplayer().seek(elapsed+time);
}
function mycarousel_initCallback(carousel) {
$('.jcarousel-control a').click(function() {
carousel.scroll($.jcarousel.intval($('.jcarousel-control a').index($(this))));
//console.log($('.jcarousel-control a').index($(this)))
return false;
});
}
$(document).ready(function() {
var tm = <?php echo $tm; ?>;
var duration = <?php echo $duration; ?>;
//console.log(duration);
var video_id = <?php echo $video_id; ?>;
var task_id = <?php echo $task_id; ?>;
var interface_id = <?php echo $interface_id; ?>;
var log = log4javascript.getLogger();
var ajaxAppender = new log4javascript.AjaxAppender("ajax-add-log.php");
log.addAppender(ajaxAppender);
log.info(formatBrowseLog(video_id, interface_id, task_id, "<?php echo $_SESSION['username']; ?>", "open", "page"));
$("#duration").html(getTimeDisplay(duration));
$( "#tabs" ).tabs();
$("#play-button").click(function(){
if ($("#play-button i").hasClass("icon-play")){
jwplayer().play();
log.info(formatBrowseLog(video_id, interface_id, task_id, "<?php echo $_SESSION['username']; ?>", "click", "play", "#play-button"));
} else {
jwplayer().pause();
log.info(formatBrowseLog(video_id, interface_id, task_id, "<?php echo $_SESSION['username']; ?>", "click", "pause", "#play-button"));
}
return false;
});
// Play button next to thumbnails
$(".seek").click(function() {
// get your id here
var id = parseInt(this.id.substring(4));
if (id < 5) id = 5; // seek does not accept negative integers
jwplayer().seek(id - 5);
log.info(formatBrowseLog(video_id, interface_id, task_id, "<?php echo $_SESSION['username']; ?>", "click", "seek", id));
return false;
});
// handling popover shown on the timeline viz
$("body").on("mouseenter", ".vt-popover", function(){
var index = parseInt($(this).css("z-index"));
$(this).css("z-index", index+1);
$(this).find(".vt-popover-inner").addClass("popover-highlight");
});
// handling popover shown on the timeline viz
$("body").on("mouseleave", ".vt-popover", function(){
var index = parseInt($(this).css("z-index"));
$(this).css("z-index", index-1);
$(this).find(".vt-popover-inner").removeClass("popover-highlight");
});
// tiny markers on the timeline slider
$("#control-center").on("click", ".marker", function(){
var id = parseInt(this.id.substring(6));
if (id < 5) id = 5;
jwplayer().seek(id - 5);
log.info(formatBrowseLog(video_id, interface_id, task_id, "<?php echo $_SESSION['username']; ?>", "click", "control-center marker", id));
return false;
});
$( "#timeline-bottom" ).slider({
range: "min",
min: 0,
max: parseInt(duration),
step: 0.1,
animate: true,
slide: function(event, ui){
jwplayer().seek(ui.value);
log.info(formatBrowseLog(video_id, interface_id, task_id, "<?php echo $_SESSION['username']; ?>", "click", "slider", ui.value));
}
});
var labels = <?php echo json_encode($labels); ?>;
var tabs1_html = tabs2_html = tabs3_html = "";
var tabs4_html = "<ul id='mycarousel' class='jcarousel-skin-tango'>";
var control_html = "<div class='jcarousel-control'>";
var text_html = "";
$.each(labels, function(index, label){
// 1. Adding Time Markers
var id = "marker" + label.tm;
var tm_formatted = getTimeDisplay(parseInt(label.tm));
//var offset = parseInt(label.tm) * control_width / duration;
var offset = parseInt(label.tm * 100) / duration;
var html = "<span class='marker' id='" + id + "' style='left:" + offset + "%;'></span>";
$("#control-center").append(html);
// 1.1 Adding idle markers
if (label.type == "image" && label.comment == "#initial") {
html = "<span class='idle-marker idle-marker-left' style='width:" + offset + "%;'></span>";
$("#control-center").append(html);
} else if (label.type == "image" && label.comment == "#final") {
html = "<span class='idle-marker idle-marker-right' style='width:" + (100-offset) + "%;left:" + offset + "%;'></span>";
$("#control-center").append(html);
}
// 2. Adding popovers
var popover_position = "";
var popover_content = "";
if (label.type == "image") {
// adding idle marker
$("#" + id).addClass("marker-image");
popover_position = "bottom";
popover_content = "<p><a id='a" + id + "' class='popover-click-image' href='#'><img class='timeline-popover' src='" + label.thumbnail + "'></a></p>";
} else {
$("#" + id).addClass("marker-tool");
popover_position = "top";
popover_content = "<p><a id='a" + id + "' class='popover-click-tool' href='#'>" + formatTool(label.tool, "toolname-block") + "</a></p>";
}
html = "<div class='vt-popover " + popover_position + "' data-offset='" + offset + "' style='left: " + offset + "%; display: block; z-index: 1010;'>"
+ "<div class='arrow'></div>"
+ "<div class='vt-popover-inner'>"
+ "<h3 class='vt-popover-title'>" + tm_formatted + " " + label.comment + " </h3>"
+ "<div class='vt-popover-content'>" + popover_content + "</div>"
+ "</div>"
+ "</div>";
$("#" + id).after(html);
// 3. Adding Marker Sticks that connect markers with popovers
id = "marker-stick" + label.tm;
var stick_class = "marker-stick-";
if (label.type == "image")
stick_class = stick_class + "image";
else
stick_class = stick_class + "tool";
html = "<span class='marker-stick " + stick_class + "' id='" + id + "' style='left:" + offset + "%;'></span>";
$("#control-center").append(html);
// 4. Adding tabbed views and HTML Tutorial
var url = "browse.php?vid=" + <?=$video_id?> + "&tm=" + label.tm;
var thumb_html = "<a href='" + label.thumbnail + "'><img src='" + label.thumbnail + "?rand=" + Math.random() + "'></a>";
var play_html = "<a class='seek btn' id='time" + label.tm + "'href='#'><i class='icon-play'></i></a>";
if (label.comment == "#initial")
tabs1_html = tabs1_html + "<div class='browse-initial'>Initial Image " + play_html + "<br>" + thumb_html + "</div>";
if (label.comment == "#final")
tabs1_html = tabs1_html + "<div class='browse-final'>Final Image " + play_html + "<br>" + thumb_html + "</div>";
if (label.type == "image") {
tabs2_html = tabs2_html + "<div class='browse-wip'>(" + tm_formatted + ") " + play_html + "<br>" + thumb_html + "</div>";
tabs3_html = tabs3_html + "<div class='browse-steps-image'>(" + tm_formatted + ") " + play_html + "<br>" + thumb_html + "</div>";
tabs4_html = tabs4_html + "<li>" + thumb_html + "</li>";
control_html = control_html + "<a href='#' class='marker-image'>" + tm_formatted + "</a> ";
//text_html = text_html + "<li class='span8'><h3>Step " + parseInt(index+1) + "</h3>" + thumb_html + "</li>";
text_html = text_html + "<li class='span8'>" + thumb_html + "<br><br><br></li>";
} else {
tabs3_html = tabs3_html + "<div class='browse-steps-tool'>(" + tm_formatted + ") " + play_html + "<br><b>" + label.tool + "</b></div>";
tabs4_html = tabs4_html + "<li><b>" + label.tool + "</b><br>" + thumb_html + "</li>";
control_html = control_html + "<a href='#' class='marker-tool'>" + tm_formatted + "</a> ";
//text_html = text_html + "<li class='span8'><h3>Step " + parseInt(index+1) + "</h3><div><b>" + label.tool + "</b></div><br>" + thumb_html + "</li>";
}
});
tabs4_html = control_html + "</div>" + tabs4_html + "</ul>";
$("#tabs-1").html(tabs1_html);
$("#tabs-2").html(tabs2_html);
$("#tabs-3").html(tabs3_html);
$("#tabs-4").html(tabs4_html);
$("#html_tutorial").html(text_html);
$(".popover-click-image, .popover-click-tool").click(function(){
var id = parseInt(this.id.substring(7));
if (id < 5) id = 5;
jwplayer().seek(id - 5);
//seek(id - 5);
log.info(formatBrowseLog(video_id, interface_id, task_id, "<?php echo $_SESSION['username']; ?>", "click", "popover-click-image popover-click-tool", id));
return false;
});
$("#mycarousel").jcarousel({
scroll: 1,
visible: 3,
initCallback: mycarousel_initCallback,
itemFirstInCallback: function(carousel, obj, index, action){
$('.jcarousel-item').eq(index).css("border", "5px solid #FF6600");
$('.jcarousel-control a').eq(index).css("border", "5px solid #FF6600");
},
itemFirstOutCallback: function(carousel, obj, index, action){
$('.jcarousel-item').eq(index).css("border", "none");
$('.jcarousel-control a').eq(index).css("border", "none");
}
});
function updatePosition(){
$(".vt-popover").each(function(index, item){
$(this).css("left", $(this).data("offset") + "%");
$(this).css("left", $(this).position().left - $(this).width()/2 + 1);
});
}
// Popover positioning upon resizing is tricky because it has both % and pixel positioning assignment
$(window).resize(function(event){
updatePosition();
});
// Getting the correct position for each popover should be done after all images are loaded.
// Otherwise prev.width() might return wrong values.
// That's why this imagesLoaded plugin is necessary.
$(".timeline-popover").imagesLoaded(function( $images, $proper, $broken ){
// TODO: error checking using $broken...
//console.log( $images.length + ' images total have been loaded in ' + this );
//console.log( $proper.length + ' properly loaded images' );
//console.log( $broken.length + ' broken images' );
updatePosition();
$(".popover-click-image").each(function(index, item){
var cur = $(this).parent().parent().parent().parent();
var cur_stick = $(".marker-stick-image").eq(index);
if (index == 0){
cur.addClass("popover-image-top");
cur_stick.addClass("marker-stick-image-top");
} else {
var prev_index = index - 1;
var prev = $(".popover-click-image:eq(" + prev_index + ")").parent().parent().parent().parent();
//console.log(index, prev.offset().left, prev.width(), cur.offset().left);
//console.log("image", prev.offset().left, prev.width(), cur.offset().left);
if (cur.position().left - prev.position().left >= prev.width()){
cur.addClass("popover-image-top");
cur_stick.addClass("marker-stick-image-top");
} else {
if (prev.hasClass("popover-image-top")){
cur.addClass("popover-image-bottom");
cur_stick.addClass("marker-stick-image-bottom");
//cur.css("margin-top", (5+prev.height()) + "px");
}
else {
cur.addClass("popover-image-top");
cur_stick.addClass("marker-stick-image-top");
}
}
}
// Now offset management: Hopefully DEPRECATED
/*
var offset = $(cur).children().eq(0).offset().left - cur_stick.offset().left;
console.log("offset", offset);
if (offset > 10 || offset < -10) {
console.log("OFFSET BUG");
//$(cur).css("left", $(cur).offset().left - offset - 5);
}
*/
});
$(".popover-click-tool").each(function(index, item){
var cur = $(this).parent().parent().parent().parent();
var cur_stick = $(".marker-stick-tool").eq(index);
if (index == 0){
cur.addClass("popover-tool-bottom");
cur_stick.addClass("marker-stick-tool-bottom");
return;
} else {
var prev_index = index - 1;
var prev = $(".popover-click-tool:eq(" + prev_index + ")").parent().parent().parent().parent();
// getting prev.width() is fine because all the content is text, so it's already loaded.
if (cur.position().left - prev.position().left >= prev.width()){
cur.addClass("popover-tool-bottom");
cur_stick.addClass("marker-stick-tool-bottom");
} else {
if (prev.hasClass("popover-tool-bottom")) {
cur.addClass("popover-tool-top");
cur_stick.addClass("marker-stick-tool-top");
} else {
cur.addClass("popover-tool-bottom");
cur_stick.addClass("marker-stick-tool-bottom");
}
}
}
});
});
// if a specific moment was designated in the url, jump to that time
if (tm >= 0) {
jwplayer().play(true);
jwplayer().seek(tm);
log.info(formatBrowseLog(video_id, interface_id, task_id, "<?php echo $_SESSION['username']; ?>", "open", "tm in url", tm));
}
var cond = "<?php echo $_GET["cond"]; ?>";
if (cond == "A")
$("#task-selector li").eq(5).addClass("active");
else
$("#task-selector li").eq(6).addClass("active");
/*
var player = null;
function playerReady(thePlayer) {
player = window.document[thePlayer.id];
player.addModelListener('STATE', 'stateEventListener');
}
// Potentially encapsulate in your player utility class
oneTimeStateEvents = [];
function addOneTimeStateEvent(playerId, targetState, f) {
var e = {
playerId: playerId // ID of player
, targetState: targetState // State to trigger on
, f: f // Function to execute
};
oneTimeStateEvents.push(e);
}
function stateEventListener(info) {
console.log(info);
for (var i = 0; i < oneTimeStateEvents.length; ) {
var e = oneTimeStateEvents[i];
// id doesn't appear to be properly set in incoming event objects?
//if (e.playerId == info.id && e.targetState == info.newstate ) {
if (e.targetState == info.newstate ) {
oneTimeStateEvents.splice(i,1); // remove event
e.f();
continue;
}
i++;
}
}
// Potentially encapsulate in your player class
function seek(time) {
var state = player.getConfig()['state'];
console.log(state);
if (state == 'IDLE') {
// Create a one time event to seek once playback starts
addOneTimeStateEvent("mediaplayer",'PLAYING',
function() {
player.sendEvent('SEEK',time);
});
player.sendEvent('PLAY', true);
}
else {
if (state == 'STOPPED') {
player.sendEvent('PLAY', true);
}
player.sendEvent('SEEK', time);
}
}
*/
jwplayer("mediaplayer").setup({
flashplayer: "js/libs/jwplayer/player.swf",
width: "900",
height: "500",
controlbar: "bottom",
file: "video/<?=$video_filename;?>",
image: "<?=$json['thumbnail'];?>",
autostart: true,
plugins: {"timeslidertooltipplugin-3": {
"preview":{
'enabled':true,
'path':'video/thumbs/',
'prefix':"<?=pathinfo($video_filename, PATHINFO_FILENAME);?>",
'frequency': 3
}
}},
events: {
onTime: function(event){
$("#elapsed").html(getTimeDisplay(parseInt(event.position)));
$("#timeline-bottom").slider('value', event.position);
},
onPlay: function(event){
$("#play-button i").removeClass("icon-play").addClass("icon-pause");
log.info(formatBrowseLog(video_id, interface_id, task_id, "<?php echo $_SESSION['username']; ?>", "click", "mediaplayer played", jwplayer().getPosition()));
},
onPause: function(event){
$("#play-button i").removeClass("icon-pause").addClass("icon-play");
log.info(formatBrowseLog(video_id, interface_id, task_id, "<?php echo $_SESSION['username']; ?>", "click", "mediaplayer paused", jwplayer().getPosition()));
},
onFullscreen: function(event){
log.info(formatBrowseLog(video_id, interface_id, task_id, "<?php echo $_SESSION['username']; ?>", "click", "mediaplayer fullscreen", event.fullscreen));
},
onError: function(event){
log.info(formatBrowseLog(video_id, interface_id, task_id, "<?php echo $_SESSION['username']; ?>", "error", "mediaplayer error", event.message));
},
onMute: function(event){
log.info(formatBrowseLog(video_id, interface_id, task_id, "<?php echo $_SESSION['username']; ?>", "click", "mediaplayer mute", ""));
},
onComplete: function(event){
log.info(formatBrowseLog(video_id, interface_id, task_id, "<?php echo $_SESSION['username']; ?>", "complete", "mediaplayer complete", ""));
},
onVolume: function(event){
log.info(formatBrowseLog(video_id, interface_id, task_id, "<?php echo $_SESSION['username']; ?>", "click", "mediaplayer volume", event.volume));
},
}
});
}); // ready
</script>
<!-- END OF THE PLAYER EMBEDDING -->
<!--
<script>
var _gaq=[['_setAccount','UA-XXXXX-X'],['_trackPageview']];
(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];
g.src=('https:'==location.protocol?'//ssl':'//www')+'.google-analytics.com/ga.js';
s.parentNode.insertBefore(g,s)}(document,'script'));
</script>
-->
</body>
</html>