video-play.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. const fileType = {
  2. "pptx": "fa-file-powerpoint-o",
  3. "ppt": "fa-file-powerpoint-o",
  4. "docx": "fa-file-word-o",
  5. "doc": "fa-file-word-o",
  6. "xls": "fa-file-excel-o",
  7. "xlsx": "fa-file-excel-o",
  8. "pdf": "fa-file-pdf-o",
  9. "zip": "fa-file-archive-o",
  10. "rar": "fa-file-archive-o",
  11. "png": "fa-file-image-o",
  12. }
  13. $(document).ready(function () {
  14. getVideoInfo();
  15. getVideoFile();
  16. $('#video').bind('contextmenu', function () {
  17. return false;
  18. });
  19. setListHeight();
  20. });
  21. $(window).resize(function () {
  22. setListHeight();
  23. });
  24. $(".sidebar-toggle").click(function () {
  25. setTimeout(function () {
  26. setListHeight();
  27. }, 10);
  28. });
  29. function getVideoInfo() {
  30. $.ajax({
  31. url: "./script/php/video/getInfo.php",
  32. type: "POST",
  33. data: {
  34. id: id,
  35. },
  36. dataType: "json"
  37. }).done(function (result) {
  38. getDescription(result[0].description);
  39. getVideoList(result[0].dir_name);
  40. }).error(function (error) {
  41. console.log(error);
  42. });
  43. }
  44. function getVideoList(dir) {
  45. $.ajax({
  46. url: "./script/php/video/getList.php",
  47. type: "POST",
  48. data: {
  49. dir: dir,
  50. },
  51. dataType: "json"
  52. }).done(function (result) {
  53. let videos = result["Video_Table"];
  54. let files = result["File_Table"];
  55. $("#video-list").empty();
  56. for (j = 0; j < videos.length; j++) {
  57. if (videos[j].file_path.includes(".m3u8")) {
  58. if (videos[j].id == id)
  59. $("#video-list").append("<li><a class='list-a' style='color:#0088CC;background-color:#B3E5FF' href = '#' onclick='getVideo(" + videos[j].id + ", \"" + folder + "\")'><i class = 'fa fa-video-camera'></i><span>" + videos[j].title + '</span></a></li>');
  60. else
  61. $("#video-list").append("<li><a class='list-a' style='color:#0088CC;' href = '#' onclick='getVideo(" + videos[j].id + ", \"" + folder + "\")'><i class = 'fa fa-video-camera'></i><span>" + videos[j].title + '</span></a></li>');
  62. }
  63. }
  64. for (j = 0; j < files.length; j++) {
  65. $("#file-list").append("<li><a class='list-a' style='color:#0088CC;' class='video' href = '#' onclick='getFile(" + files[j].id + ")'><i class = 'fa " + fileType[files[j].type] + "'></i><span>" + files[j].title + "." + files[j].type + '</span></a></li>');
  66. }
  67. }).error(function (error) {
  68. console.log(error);
  69. });
  70. }
  71. function getDescription(description) {
  72. if (description == null) {
  73. description = "暫無描述";
  74. }
  75. $("#description").text(description);
  76. }
  77. function setListHeight() {
  78. $("#video-list-panel").height($("#video-body").height() * 0.7);
  79. $("#file-list-panel").height($("#video-body").height() * 0.3);
  80. }
  81. function getVideoFile() {
  82. $.ajax({
  83. url: "./script/php/video/getVideoFile.php",
  84. type: "POST",
  85. data: {
  86. id: id,
  87. },
  88. }).done(function (result) {
  89. var video = videojs("video");
  90. video.src({
  91. src: result,
  92. });
  93. video.on("canplay", function () {
  94. video.poster(result.replace("m3u8", "jpg"));
  95. });
  96. }).error(function (error) {
  97. console.log("e:" + error);
  98. });
  99. }
  100. function getFile(id) {
  101. window.location.href = "./script/php/video/getFile.php?id=" + id;
  102. }
  103. function getVideo(id, folder) {
  104. $.redirect('./video-play.php', {
  105. 'id': id,
  106. 'folder': folder,
  107. });
  108. }
  109. function returnToList(folder) {
  110. $.redirect('./video-list.php', {
  111. 'folder': folder
  112. });
  113. }