forked from gdroberts/rashomon
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathrashomon.js
1260 lines (1140 loc) · 38.1 KB
/
rashomon.js
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
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
rashomon
copyleft 2012
*/
var Rashomon = {
manifestLoc: "davis.json",
adjustable: true,
manifest: {},
videos: [],
photos: [],
phometa: [],
photoDuration: 10,
loaded: 0,
looping: false,
startLoop: 0,
endLoop: 0,
delayFixed: 0,
nullp: 0,
fulldur: 0,
tallest: 0,
fs: 0,
preoffset: 0,
solomode: false,
earliest: new Date(),
timeline: "",
videosToDisplay: "",
colorList: ["red", "#E88C03", "#CAEB47", "#1C9928", "#4789EB", "#60f", "magenta", "Khaki", "turquoise"],
validDate: function (item) {
//makes sure date isn't from 1904 or 1946 (ENIAC) or sometime way before videos existed
if (item.mcDate > 2000) {
return item.mcDate;
} else {
return item.fmDate;
}
},
getVidById: function (id) {
id = parseInt(id, 10);
var h = {};
$(this.videos).each(function (k, v) {
if (v.id === id) {
h = this;
}
});
return h;
},
getPhoById: function (id) {
id = parseInt(id, 10);
var h = {};
$(this.photos).each(function () {
if (this.id === id) {
h = this;
}
});
return h;
},
extendBefore: function (sec) {
this.fulldur += sec;
this.nullp.src = "#t=," + this.fulldur;
this.preoffset += sec;
this.startLoop += sec;
this.earliest = moment(this.earliest).add('s', sec).toDate();
Rashomon.setupLoop(Rashomon.startLoop, Rashomon.endLoop);
$(this.videos).each(function () {
if (this.id !== Rashomon.dragId) {
this.offset += sec;
this.drawVidtimes();
}
});
},
makeDraggable: function () {
$(".vidtime, .photime").draggable({
start: function () {
Rashomon.dragId = $(this).attr('data-id');
$(this).removeClass('moveTransition');
},
stop: function () {
var aPhoto, left;
Rashomon.dragId = -1;
Rashomon.getVidById($(this).attr('data-id')).offset = Rashomon.offset2time($(this).position().left);
$(this).addClass('moveTransition');
if ($(this).hasClass("vidtime")) {
$(Rashomon.videos).each(function () {
this.changeStuff();
});
//aVid.changeStuff(Rashomon.offset2time(left));
} else {
console.log($(this).attr('class'));
aPhoto = Rashomon.getPhoById($(this).attr('data-id'));
left = $(this).position().left;
aPhoto.changeStuff(Rashomon.offset2time(left));
}
console.log("end of stop");
},
drag: function (event, ui) {
if (ui.position.left <= 0) {
Rashomon.extendBefore(5);
} else if ($(this).parent().width() - (ui.position.left + $(this).width()) < 5) {
Rashomon.extendAfter(5);
}
},
containment: "parent",
cursor: "-moz-grabbing pointer"
});
},
extendAfter: function (sec) {
this.fulldur += sec;
this.nullp.src = "#t=," + this.fulldur;
$(this.videos).each(function () {
if (this.id !== Rashomon.dragId) {
this.drawVidtimes();
}
});
Rashomon.setupLoop(Rashomon.startLoop, Rashomon.endLoop);
},
loadFullscreen: function (id) {
var vid = this.getVidById(id);
var ctime = Popcorn("#video" + id).currentTime();
var sources = [vid.mp4, vid.webm];
$(sources).each(function () {
var src = $(this).attr("src");
$(this).attr("src", src.replace("small", "large"));
});
if (!sources) {
alert("Something wrong with sources for this video");
}
Rashomon.timeline.pause();
//$('body').css('overflow', "hidden");
Rashomon.fs = $("<video/>", {
'id': 'fsvid',
"controls": true
}).css("opacity", "1").appendTo("#videos");
$(sources).each(function () {
$(this).appendTo(Rashomon.fs);
});
Rashomon.fs.css("opacity", 1).fullScreen(true);
Rashomon.fspop = Popcorn("#fsvid");
Rashomon.fspop.playbackRate(Rashomon.timeline.playbackRate());
Rashomon.fspop.on("loadedmetadata", function () {
Rashomon.fspop.pause(ctime);
});
},
offset2time: function (offset) {
var pct = offset / $('#maintimeline').width();
var tldur = Rashomon.fulldur;
this.nullp.src = "#t=," + tldur;
return (tldur * pct);
},
getPct: function (offset) {
return (offset / $("#maintimeline").width() * 100);
},
//initiates loop, times determined by media or media fragment uri
setupLoop: function (start, finish) {
var startPos = Rashomon.getOffset(start);
var finishPos = Rashomon.getOffset(finish);
Rashomon.looping = true;
Rashomon.startLoop = start;
Rashomon.endLoop = finish;
Rashomon.timeline.cue(Rashomon.endLoop, function () {
Rashomon.timeline.play(Rashomon.startLoop);
});
//add movers to timeline, set up slider
var leftMover = $("<div/>", {
"id": "leftMover",
"class": "mover ui-slider-handle",
"text": "\u25bc"
}).appendTo("#maintimeline");
var rightMover = $("<div/>", {
"id": "rightMover",
"class": "mover ui-slider-handle",
"text": "\u25bc"
}).appendTo("#maintimeline");
$(".mover").css({
"background": "transparent",
"border": "0",
"margin-left": "-8px",
"margin-top": "-12px",
"color": "black",
"cursor": "pointer"
});
$(".ui-slider-range").css({
"position": "relative",
"height": "100%",
"border": "0",
"border-radius": 0,
"background": "url('images/reel.png') top left repeat-x"
});
$("#maintimeline").css({
"border-radius": "0"
});
//make the loop selector
$("#maintimeline").slider({
range: true,
min: 0,
max: Rashomon.fulldur,
values: [start, finish],
change: function (event, ui) {
var value = ui.values;
Rashomon.startLoop = ui.values[0];
Rashomon.endLoop = ui.values[1];
//abstract this into a function that can deal with whether change was manual (using sliders) or via drag event.
var t = $.url().attr("query", "t=18,19");
var url = $.url().attr('source').replace(t, "");
//console.log(url);
url = "?t=" + ui.values[0] + "," + (ui.values[1] - ui.values[0]);
history.pushState(null, null, url);
//console.log(url);
Rashomon.timeline.cue("loop", value[1], function () {
//console.log("reached end of loop");
if (!Rashomon.timeline.media.paused) {
//console.log("adjusting");
Rashomon.timeline.currentTime(value[0]);
}
}); //end cue
//move if currentTime is out of bounds
//console.log(value);
if (Rashomon.timeline.currentTime() < value[0] || Rashomon.timeline.currentTime() > value[1]) {
Rashomon.timeline.currentTime(value[0]);
if (Rashomon.timeline.media.paused) {
$(Rashomon.videos).each(function () {
this.seekPaused();
});
} //end if
} //end if
} //end slider
}).css({
"border": "0",
"border-bottom": "1px solid #666"
});
},
//formats exifTool's dates to something javascript Date object can use
formatDate: function (exifDate) {
if (!exifDate) {
return false;
}
var momentDate = moment(exifDate, "YYYY:MM:DD HH:mm:ss Z");
return momentDate.toDate();
//input format looks like "YYYY:MM:DD HH:MM:SS:mm-05:00" (-05:00 is timezone)
},
//converts seconds to hh:mm:ss
sec2hms: function (time) {
var totalSec = parseInt(time, 10);
var hours = parseInt(totalSec / 3600, 10) % 24;
var minutes = parseInt(totalSec / 60, 10) % 60;
var seconds = parseInt(totalSec % 60, 10);
return (hours < 10 ? "0" + hours : hours) + ":" + (minutes < 10 ? "0" + minutes : minutes) + ":" + (seconds < 10 ? "0" + seconds : seconds);
},
//deals with various duration metadata standards
formatDuration: function (duration) {
if (!duration) {
return false;
}
var dur;
//because having different cameras output duration in the same format would be crazy!
if (duration.indexOf(":") !== -1) {
//return Popcorn.util.toSeconds(duration)
var split = duration.split(":");
var hr = split[0];
var min = split[1];
var sec = +split[2];
dur = (hr * 60 * 60) + (min * 60) + sec;
return dur;
} else if (duration.indexOf("s") !== -1) {
var seconds = duration.split(".");
dur = seconds[0];
return dur;
} else {
console.log("Some weird duration, couldn't format");
}
},
//coordinate conversion for GPS metadata
convertCoord: function (coord) {
var split = coord.split(" ");
if (split[1] === "S" || split[1] === "W") {
return split[0] * -1;
} else {
return split[0];
}
},
isEven: function (someNumber) {
return (someNumber % 2 === 0) ? "even" : "odd";
},
finalize: function () {
var rate = $('#rateControl').val();
Rashomon.timeline.playbackRate(rate);
$("#theRate").text("Playback rate: " + Math.round(rate * 100) + "%");
$(".container").each(function () {
$(this).css("height", Rashomon.tallest + 8);
});
$("#loading").hide();
$(this.videos).each(function () {
this.pp.off("canplaythrough");
this.pp.off("suspend");
this.setupVid();
});
$(this.photos).each(function () {
this.setupPho();
});
$("#timepos").on("mousedown", function () {
if (!Rashomon.timeline.media.paused) {
Rashomon.resume = true;
}
Rashomon.timeline.pause();
});
$(Rashomon.videos).each(function () {
this.seekPaused();
});
//console.log("Finished setting up");
$("#timeDisplay").fadeIn();
$("#timeDisplay").css({
"margin-left": "-" + $("#timeDisplay").width() / 2 + "px"
});
var newheight = $("#maintimeline").offset().top + $("#maintimeline").height() - $(".lines").first().offset().top;
//set up time position draggable events
$("#timepos").draggable({
"containment": "parent",
"axis": "x",
"start": function (event, ui) {
if (!Rashomon.timeline.media.paused) {
Rashomon.resume = true;
}
Rashomon.timeline.pause();
},
"drag": function (event, ui) {
console.log(ui.position.left);
$("#timeDisplay").css({
left: ui.position.left
});
var pct = ui.position.left / $('#maintimeline').width();
$("#timeDisplay").text(Rashomon.sec2hms(Rashomon.fulldur * pct));
},
"stop": function (event, ui) {
var pct = $("#timepos").position().left / $('#maintimeline').width();
var tldur = Rashomon.fulldur;
Rashomon.timeline.currentTime(tldur * pct);
if (Rashomon.resume) {
Rashomon.timeline.play();
Rashomon.resume = false;
} else {
$(Rashomon.videos).each(function () {
this.seekPaused();
});
}
}
});
//not fond of this, but it seems to keep playhead from locking. using better event than metadataloaded could help?
$("#timepos").css({
"height": newheight,
"cursor": "pointer"
});
$("#timepos").show();
$(".vidnum, .phonum").addClass("vidactive");
var url = $.url();
//detects for Media Fragment uri (?t=15,5 returns a 5 second loop starting at 15 seconds)
if (url.attr("query")) {
var frag = url.attr("query");
frag.replace("t=", "");
var fragtemp = frag.split("=");
fragtemp = fragtemp[1].split(",");
var loopStart = parseInt(fragtemp[0], 10);
var loopEnd = parseInt(loopStart + parseInt(fragtemp[1], 10), 10);
Rashomon.setupLoop(loopStart, loopEnd);
} else {
Rashomon.setupLoop(0, Rashomon.fulldur - 5);
}
Rashomon.setupEvents();
Rashomon.timeline.play(Rashomon.startLoop);
},
//sets up the timeline element and loads each video, determines timescope based on its contents
setupTimeline: function (duration) {
$("<div/>", {
"id": "loading",
"text": "Loading..."
}).css({
"position": "absolute",
"top": "35%",
"left:": "45%",
'text-align': 'center',
"font-size": '3em',
"color": "black",
"z-index": "120",
"width": "auto",
"height": "auto",
"margin-left": "300px",
"background": 'rgba("255,255,255,0.73")',
"text-shadow": "3px 5px 5px #666"
}).appendTo("#vidlines");
console.log("Setting up timeline.");
this.nullp = Popcorn.HTMLNullVideoElement("#maintimeline");
this.nullp.src = "#t=,123.12";
this.timeline = Popcorn(this.nullp);
$("#eventTitle").text(Rashomon.eventName);
Rashomon.timeline.cue("loop");
//setup photos
$(Rashomon.photos).each(function () {
this.buildPhotoViewer();
});
//setup videos
$(Rashomon.videos).each(function () {
//console.log("building video player " + this.id);
this.buildVideoPlayer();
//console.log("built");
//lower volume
this.pp.volume(0.33);
//once metadata has loaded, read video timing/size metadata and add video to timeline
}); //end each
var readies = 0;
$(this.videos).each(function () {
var thevid = this;
this.pp.on('suspend', function () {
//console.log("Vid " + thevid.id + " has suspended.");
this.currentTime(0.00);
});
this.pp.on('canplaythrough', function () {
//console.log(thevid.id + " is ready.");
thevid.cpt = 1;
readies = 0;
if (this.media.videoHeight > Rashomon.tallest) {
Rashomon.tallest = this.media.videoHeight;
}
$(Rashomon.videos).each(function () {
if (this.cpt) {
$("#vidtime" + this.id).css("opacity", 1);
readies++;
}
$("#loading").text("Loading... " + parseInt(readies / Rashomon.videos.length * 100, 10) + "%");
if (readies === Rashomon.videos.length) {
Rashomon.finalize();
}
});
});
}); //end bind
this.timeline.currentTime(0); //Start at beginning of timeline,
this.fulldur = duration; // end of final video
this.nullp.src = "#t=," + this.fulldur;
//When timeline plays...
this.timeline.on("play", function () {
//make sure it is within the loop selection
if (Rashomon.timeline.currentTime() < Rashomon.startLoop || Rashomon.timeline.currentTime() > Rashomon.endLoop) {
Rashomon.timeline.currentTime(Rashomon.startLoop);
}
//toggle buttons
$("#play").hide();
$("#stop").show();
//each video checks to see if it should play
$(Rashomon.videos).each(function () {
var offset = this.offset;
var duration = this.pp.duration();
if (Rashomon.timeline.currentTime() > offset && Rashomon.timeline.currentTime() < offset + duration && !$("#vcontain" + this.id).is(":hidden")) {
this.pp.play();
}
}); // end videos each
}); //end play
//when timeline pauses...
this.timeline.on("pause", function () {
//toggle buttons
$("#play").show();
$("#stop").hide();
//pause all videos (no need to check if already paused)
$(Rashomon.videos).each(function () {
this.pp.pause(Rashomon.timeline.currentTime() - this.offset);
});
}); //end pause
/*
this.timeline.cue(Rashomon.fulldur - 0.01, function () {
Rashomon.timeline.pause();
console.log("pausing");
}); //end cue */
//play button behavior
$("#play").click(function () {
//console.log(Rashomon.timeline.currentTime() + "of " + Rashomon.fulldur);
if (Rashomon.timeline.currentTime() < Rashomon.fulldur) {
Rashomon.timeline.play();
}
});
//pause media when stop button is pressed
$("#stop").click(function () {
Rashomon.timeline.pause();
});
$("#forward").click(function () {
//reduced so it doesn't trigger the loop rewind
Rashomon.timeline.pause(Rashomon.endLoop - 0.5);
});
$("#rewind").click(function () {
Rashomon.timeline.currentTime(Rashomon.startLoop);
});
//adjust playhead when main timeline moves
Rashomon.timeline.on("timeupdate", function () {
if (this.currentTime() > Rashomon.fulldur - 0.5) {
this.pause(Rashomon.fulldur - 0.5);
}
//if you glitch and pass the loop endtime,
var pct = this.currentTime() / Rashomon.fulldur * 100; // for when we switch to % for window size adjustments
$("#timeloc, #timeDisplay").text(Rashomon.sec2hms(this.currentTime()));
$("#timepos, #timeDisplay").css('left', pct + "%");
});
//on navtl click, adjust video positions appropriately, obeying play conditions and such
},
getOffset: function (time) {
return $("#maintimeline").width() * time / Popcorn.util.toSeconds(this.fulldur);
},
// reads videos from rashomonManifest object, which is created by another hunk of js linked in the html
setupVideos: function () {
console.log("Setting up videos");
var l = Rashomon.vidmeta.length;
$.each(Rashomon.vidmeta, function (index, item) {
if (item.duration === null) {
item.duration = 30;
}
Rashomon.videos.push(new video({
"offset": parseInt(item.offset, 10),
"duration": parseInt(item.duration, 10),
"id": index,
"file": item.name
}));
/*
var aphoto = Rashomon.photos.push(new photo({
{
"offset": item.vDate.getTime() / 1000,
"id": index,
"file": item.filename,
"meta": itemdata[0]
}));
*/
l--;
if (Rashomon.videos.length === Rashomon.vidmeta.length) {
//console.log("Finished last file");
$.each(Rashomon.videos, function () {
var id = this.id;
$('#video' + id).attr('data-offset', this.offset);
var extend = this.duration + this.offset + 15;
if (extend > Rashomon.fulldur) {
Rashomon.fulldur = extend;
Rashomon.photoDuration = extend / 60;
if (Rashomon.photoDuration < 5) {
Rashomon.photoDuration = 5;
}
}
});
} // end if
}); //end getJSON (per item)
}, //end setupVideos
setupPhotos: function () {
console.log("setting up photos");
var l = Rashomon.phometa.length;
$.each(Rashomon.phometa, function (index, item) {
Rashomon.photos.push(new photo({
"offset": parseInt(item.offset, 10),
"id": index + Rashomon.videos.length,
"file": item.name
}));
l--;
if (Rashomon.photos.length === Rashomon.phometa.length) {
//console.log("Finished last file");
$.each(Rashomon.photos, function () {
//$('#photo' + id).attr('data-offset', this.offset);
var extend = this.duration + this.offset + 15;
if (extend > Rashomon.fulldur) {
Rashomon.fulldur = extend;
}
});
} // end if
}); //end each
},
setupEvents: function () {
//console.log("setting events");
$(".vidtl").click(function (e) {
var clickleft = e.pageX - $('#maintimeline').offset().left;
var pct = clickleft / $('#maintimeline').width();
Rashomon.timeline.currentTime(Rashomon.fulldur * pct);
if (Rashomon.timeline.media.paused) {
$(Rashomon.videos).each(function () {
this.seekPaused();
});
}
}); //end nav click
$(".vidnum").click(function () {
var vidId = $(this).attr("data-id");
Rashomon.getVidById(vidId).toggleStatus();
}); // end vidnum click
$(".phonum").click(function () {
var phoId = $(this).attr("data-id");
Rashomon.getPhoById(phoId).toggleStatus();
}); // end vidnum click
$(".container").hover(function () {
$(this).find(".tools").fadeIn("fast");
}, function () {
$(this).find(".tools").fadeOut("fast");
});
$(".audbutton").click(function () {
var action = $(this).attr('data-audio');
var id = $(this).attr('data-id');
if (action !== "solo") {
$(".solo").removeClass("audactive");
console.log("setting " + id + " to " + action);
Rashomon.getVidById(id).audStatus = action;
}
$(this).addClass("audactive");
$(this).siblings("i").removeClass("audactive");
if (action === "mute") {
if (Rashomon.solomode) {
$(".solo").removeClass("audactive");
$(Rashomon.videos).each(function () {
if (this.id !== id) {
this.revertAudio();
}
});
}
Rashomon.getVidById(id).pp.mute();
Rashomon.solomode = false;
} else if (action === "speaker") {
Rashomon.getVidById(id).pp.unmute();
if (Rashomon.solomode) {
$(".solo").removeClass("audactive");
$(Rashomon.videos).each(function () {
if (this.id !== id) {
this.revertAudio();
}
});
Rashomon.solomode = false;
}
} else if (action === "solo") {
Rashomon.getVidById(id).audStatus = "solo";
Rashomon.solomode = true;
$(Rashomon.videos).each(function () {
if (this.id !== id) {
this.soloMute();
}
});
Rashomon.getVidById(id).pp.unmute();
}
}); // end audButton
$(".locker").click(function () {
var id = $(this).attr("data-id");
if ($(this).hasClass("icon-lock")) {
Rashomon.getVidById(id).makeDraggable();
$(this).removeClass("icon-lock").addClass("icon-unlock");
} else {
Rashomon.getVidById(id).makeUndraggable();
$(this).removeClass("icon-unlock").addClass("icon-lock");
}
});
}
};
var photo = function (options) {
this.offset = options.offset;
this.name = options.file;
this.file = options.file;
this.id = options.id;
this.color = Rashomon.colorList[this.id];
this.meta = options.meta;
this.url = Rashomon.mpath + this.file + "_small.jpg";
};
photo.prototype = {
setupPho: function () {
var of = this.offset;
//console.log(pid + ": " + height + " x " + width);
Rashomon.timeline.rashomonPhoto({
"id": this.id,
"timeline": Rashomon.timeline,
"start": of,
"end": of + Rashomon.photoDuration
});
this.eventId = Rashomon.timeline.getLastTrackEventId();
//console.log("should fire at " + of + "for 5 seconds");
},
showPhoto: function () {
$("#pContainer" + this.id).show("fast", "linear");
},
hidePhoto: function () {
if ($("#pContainer" + this.id).is(":visible")) {
$("#pContainer" + this.id).hide("fast", "linear");
}
},
showMeta: function () {
$("#meta").css("right", "0");
//console.log(this.meta);
$("#metadata ul").remove();
var list = $("<ul/>");
$("<li/>", {
text: "Filename : " + this.file
}).appendTo(list);
$("<li/>", {
text: "Start time: " + this.meta.MediaCreateDate
}).appendTo(list);
$("<li/>", {
text: "Offset: " + this.offset + "s"
}).appendTo(list);
$("<li/>", {
text: "..."
}).appendTo(list);
list.appendTo("#metadata");
},
buildPhotoViewer: function () {
var pContainer = $("<div/>", {
id: "pContainer" + this.id,
'class': 'container'
}).css("border-color", Rashomon.videos.length + Rashomon.colorList[this.id]);
var tools = $("<div/>", {
'class': 'tools'
});
var image = $("<img/>", {
id: "photo" + this.id,
"class": 'rashomon',
"data-offset": this.offset,
"data-id": this.id,
"src": this.url
});
pContainer.appendTo("#videos");
image.appendTo(pContainer);
tools.html("<em>" + (this.id + 1) + "</em> <div class='tbuttons'><div><i class='fsbutton icon-fullscreen' id='fs" + this.id + "'" + "></i></div>").appendTo(pContainer);
// <img src='images/info.png' class='showmeta' id='meta" + this.id + "'>")
//make display function for timeline thing
//call popcorn plugin
$("#meta" + this.id).click(function () {
photo.showMeta();
return false;
});
}, // end viewer
displayPhoto: function () {
$("#pholines").show();
var id = this.id;
var offset = this.offset;
var position = Rashomon.getOffset(offset);
var leftpos = position;
var pholine = $("<div/>", {
"class": "pholine " + Rashomon.isEven(id),
"id": "pholine" + id
});
$("<div/>", {
"class": "phonum",
"id": "pho" + id,
"text": +id + 1,
"data-id": id,
title: "Click to toggle photo"
}).appendTo(pholine);
var photl = $("<div/>", {
"class": "vidtl",
"id": "tl" + id,
"data-id": id
}).appendTo(pholine);
$("<img/>", {
"class": "photime moveTransition",
"id": "photime" + id,
"data-id": id,
"title": this.file,
"src": this.url
}).css({
"left": leftpos / $("#maintimeline").width() * 100 + "%",
"height": "100%"
}).appendTo(photl);
pholine.appendTo("#pholines .lines");
$('.pholine').tsort({
attr: 'id'
});
this.drawPhotimes();
},
toggleStatus: function () {
if ($("#pho" + this.id).hasClass("vidactive")) {
$("#pho" + this.id).removeClass("vidactive");
$("#pho" + this.id).addClass("vidinactive");
$("#pContainerß" + this.id).hide("fast", "linear");
$("#photime" + this.id).css("opacity", "0.25");
} else {
//turn it on!
$("#pho" + this.id).addClass("vidactive");
$("#pho" + this.id).removeClass("vidinactive");
$("#photime" + this.id).css("opacity", "1");
//console.log("on " + this.id);
//console.log(Rashomon.timeline.currentTime() + " between points " + this.offset + " " + (this.offset + this.duration) + "?");
if (Rashomon.timeline.currentTime() > this.offset && Rashomon.timeline.currentTime() < (this.offset + this.duration)) {
//console.log("truth");
$("#pcontain" + this.id).show("fast", "linear");
}
}
},
drawPhotimes: function () {
}
}; // end photo
var video = function (options) {
this.offset = parseInt(options.offset, 10);
this.duration = parseInt(options.duration, 10);
this.name = options.file;
this.file = options.file;
this.id = options.id;
this.color = Rashomon.colorList[this.id];
this.meta = options.meta;
this.eventId = "";
this.cpt = 0;
this.audStatus = "speaker";
};
video.prototype = {
setupVid: function () {
var of = this.offset;
this.duration = this.pp.duration();
this.drawVidtimes();
$(this).attr('data-duration', this.duration);
var height = parseInt(this.pp.media.videoHeight, 10);
var width = parseInt(this.pp.media.videoWidth, 10);
//console.log(pid + ": " + height + " x " + width);
if (height > width) {
$("#video" + this.id).addClass("vert");
} else {
$("#video" + this.id).addClass("hor");
}
var offtime = parseInt(Popcorn.util.toSeconds(this.duration) + of, 10);
Rashomon.timeline.rashomonVideo({
"vid": this,
"timeline": Rashomon.timeline,
"start": of,
"end": offtime
});
this.eventId = Rashomon.timeline.getLastTrackEventId();
},
makeDraggable: function () {
$("#vidtime" + this.id).draggable({
start: function () {
Rashomon.dragId = $(this).attr('data-id');
$(this).removeClass('moveTransition');
},
stop: function () {
Rashomon.dragId = -1;
Rashomon.getVidById($(this).attr('data-id')).offset = Rashomon.offset2time($(this).position().left);
$(this).addClass('moveTransition');
if ($(this).hasClass("vidtime")) {
$(Rashomon.videos).each(function () {
this.changeStuff();
});
//aVid.changeStuff(Rashomon.offset2time(left));
} else {
console.log($(this).attr('class'));
var aPhoto = Rashomon.getPhoById($(this).attr('data-id'));
var left = $(this).position().left;
aPhoto.changeStuff(Rashomon.offset2time(left));
}
console.log("end of stop");
},
drag: function (event, ui) {
if (ui.position.left <= 0) {
Rashomon.extendBefore(5);
} else if ($(this).parent().width() - (ui.position.left + $(this).width()) < 5) {
Rashomon.extendAfter(5);
}
},
containment: "parent"
});
},
makeUndraggable: function () {
$("#vidtime" + this.id).draggable("destroy").css("cursor", "crosshair");
},
changeStuff: function (offset) {
if (offset) {
this.offset = offset;
}
Rashomon.timeline.removeTrackEvent(this.eventId);
Rashomon.timeline.rashomonVideo({
"vid": this,
"timeline": Rashomon.timeline,
"start": this.offset,
"end": this.offset + this.duration
});
this.eventId = Rashomon.timeline.getLastTrackEventId();
this.drawVidtimes();
},
buildVideoPlayer: function () {
var container = $("<div/>", {
id: "vcontain" + this.id,
'class': 'container'
});
var innerdiv = $("<div/>", {
'class': 'innervid'
}).appendTo(container).css("border", "4px solid " + Rashomon.colorList[this.id]);
var tools = $("<div/>", {
'class': 'tools'
}).css("background", Rashomon.colorList[this.id]);
var vid = $("<video/>", {
id: "video" + this.id,
"class": 'rashomon',
"data-offset": this.offset,
"data-id": this.id
});
this.webm = $("<source/>", {
src: Rashomon.mpath + this.file + "_small.webm",
type: 'video/webm'
});
this.mp4 = $("<source/>", {
src: Rashomon.mpath + this.file + "_small.mp4",
type: 'video/mp4'
});
this.mp4.appendTo(vid);
this.webm.appendTo(vid);
container.appendTo($("#videos"));
vid.appendTo(innerdiv);
//this one has meta button
//tools.html("<em>" + (this.id + 1) + "</em> <div class='tbuttons'><img src='images/full-screen-icon.png' + class='fsbutton' id='fs" + this.id + "'/> <img src='images/info.png' class='showmeta' id='meta" + this.id + "'>").appendTo(container);
//this one doesn't
tools.html("<span class='vidplid'>" + (this.id + 1) + "</span> <div class='tbuttons'></div>").appendTo(innerdiv);
$("<i/>", {
"class": "fsbutton icon-fullscreen",
"id": "fs" + this.id
}).appendTo(tools.find(".tbuttons"));
this.pp = Popcorn("#video" + this.id);
},
//in cases where you seek when main timeline is paused, popcorn does not run 'start' event if seeking from within another in-band event
seekPaused: function () {
this.pp.currentTime(Rashomon.timeline.currentTime() - this.offset);
},
showVid: function () {
$("#vcontain" + this.id).show("fast", "linear");
},