script.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. $(document).ready(function() {
  2. var _frames, _frames_length;
  3. var _$timelaps = $('#timelaps'), _$video = $("#timelapsvid"), _video = document.getElementById('timelapsvid'), _fps = 12, _vid_current_time;
  4. var _timeline, _timeline_container = document.getElementById('timeline'),
  5. _tl_data_ar = [], _tl_items, _tl_start, _tl_end;
  6. function init(){
  7. console.log("Init");
  8. loadData();
  9. };
  10. function loadData(){
  11. console.log('loadData');
  12. // $.getJSON('metadata/frame.json',function(data){
  13. // setUpData(data.frames)
  14. // });
  15. $.ajax({
  16. dataType:"json",
  17. url:'metadata/frames.json',
  18. cache: false,
  19. success:setUpData
  20. });
  21. console.log('getMetaData END');
  22. };
  23. function setUpData(d){
  24. console.log("setUpData");
  25. _frames = d.frames;
  26. // console.log(_frames);
  27. // for (var i in _frames) {
  28. // // console.log(data.frames[i]);
  29. // _tl_data_ar.push({
  30. // start:new Date(_frames[i].datetime),
  31. // id:_frames[i].id
  32. // });
  33. // }
  34. // console.log("_frames[_frames.length]",_frames[_frames.length-1]);
  35. _tl_start= new Date(_frames[0].datetime);
  36. _tl_end= new Date(_frames[_frames.length-1].datetime);
  37. // console.log('_tl_start : '+_tl_start+" | _tl_end"+_tl_end);
  38. initDataReady();
  39. };
  40. function initDataReady(){
  41. console.log("initDataReady");
  42. setupTimeline();
  43. setupVideoEvents();
  44. play();
  45. }
  46. function setupTimeline(){
  47. // Create a DataSet (allows two way data-binding)
  48. // _tl_items = new vis.DataSet(_tl_data_ar);
  49. // Configuration for the Timeline
  50. // var options = {};
  51. // Create a Timeline
  52. _timeline = new vis.Timeline(_timeline_container, [], {
  53. height:'50px',
  54. showCurrentTime:false,
  55. start:_tl_start,
  56. end:_tl_end,
  57. stack:false
  58. });
  59. _timeline.addCustomTime(_tl_start, "videotime");
  60. _timeline.on('click', onClickTimeline)
  61. }
  62. function onClickTimeline(props){
  63. console.log("onClickTimeline", props.time);
  64. // seekVideoTo(props.items[0]);
  65. };
  66. function moveTimelineCursor(date){
  67. _timeline.setCustomTime(date, "videotime", {animation:false});
  68. _timeline.moveTo(date, {animation:false});
  69. }
  70. function setupVideoEvents(){
  71. // console.log("setupVideoEvents");
  72. _$video.on("click", onClickVid);
  73. };
  74. function onClickVid(e){
  75. console.log("onClickVid",e);
  76. if(_video.paused){
  77. _video.play();
  78. }else{
  79. _video.pause();
  80. }
  81. };
  82. // function seekVideoTo(f){
  83. // console.log("seekVideoTo frame", f);
  84. // _video.pause();
  85. // _video.currentTime = f/_fps;
  86. // };
  87. function play(millis){
  88. requestAnimationFrame(play);
  89. // console.log("_video.playing",_video.paused);
  90. if (!_video.paused) {
  91. moveTimelineCursor(_frames[vt2f(_video.currentTime)].datetime);
  92. }
  93. // now = Date.now();
  94. // delta = now - then;
  95. //
  96. // if(delta > interval){
  97. // then = now -(delta % interval);
  98. // }
  99. }
  100. /* helpers */
  101. function vt2f(ct){
  102. // console.log("Video Time 2 frame");
  103. return Math.round(ct/(1/_fps));
  104. // console.log("frame", frame);
  105. }
  106. init();
  107. });