videos.ejs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <!DOCTYPE html>
  2. <html lang="<%= lang %>">
  3. <head>
  4. <%- include('common-meta') %>
  5. <link rel="stylesheet" href="/stylesheets/styles.css">
  6. <link rel="stylesheet" href="/stylesheets/header.css">
  7. </head>
  8. <!-- Google tag (gtag.js) -->
  9. <script async src="https://www.googletagmanager.com/gtag/js?id=G-JBGGVGLHTP"></script>
  10. <script>
  11. window.dataLayer = window.dataLayer || [];
  12. function gtag() { dataLayer.push(arguments); }
  13. gtag('js', new Date());
  14. gtag('config', 'G-JBGGVGLHTP');
  15. </script>
  16. <script src="https://cdn.jsdelivr.net/npm/hls.js@latest"></script>
  17. <body>
  18. <%- include('header') %>
  19. <h1 style="display: flex; justify-content: center; padding: 10px; color: purple">
  20. <%= title %>
  21. </h1>
  22. <h2 style="display: flex; justify-content: center; padding: 0px 10px 10px 10px; color: #333">
  23. <%= description %>
  24. </h2>
  25. <div class="content">
  26. <div class="album-icon-grid">
  27. <% data.forEach(video=> { %>
  28. <div class="album-grid-card">
  29. <div style="padding: 2px; font-size: 14px; color: grey; text-align: center; white-space: nowrap;">
  30. <%= translate.videoStory[lang] %>
  31. </div>
  32. <a href="javascript:;" onclick="onPlay(`<%= video.url %>`, `<%= video.jsonStr %>`)">
  33. <img src="<%= video.poster %>" class="album-icon-img" alt="<%= video.seoTitle %>">
  34. <img src="/assets/svg/play-button.svg" , class="video-play-button" width="20px" height="20px"
  35. alt="Coloring Page Video Play Button">
  36. </a>
  37. </div>
  38. <% }); %>
  39. </div>
  40. </div>
  41. <!-- 弹出层 -->
  42. <div id="video-popup" class="popup">
  43. <div class="popup-content-wrapper">
  44. <span class="close" onclick="closeVideoPopup()">&times;</span>
  45. <div class="popup-content-left">
  46. <video id="video-player" controls></video>
  47. </div>
  48. <div id="video-content" class="popup-content-right">
  49. </div>
  50. </div>
  51. </div>
  52. <script>
  53. function onPlay(url, videoJson) {
  54. // alert(url);
  55. // return;
  56. console.log(url);
  57. console.log(videoJson);
  58. var video = JSON.parse(`${videoJson}`);
  59. generateVideoContent(video);
  60. var videoPopup = document.getElementById('video-popup');
  61. var videoPlayer = document.getElementById('video-player');
  62. videoPopup.style.display = 'block';
  63. if (Hls.isSupported()) {
  64. var hls = new Hls();
  65. hls.loadSource(url);
  66. hls.attachMedia(videoPlayer);
  67. hls.on(Hls.Events.MANIFEST_PARSED, function () {
  68. videoPlayer.play();
  69. });
  70. } else if (videoPlayer.canPlayType('application/vnd.apple.mpegurl')) {
  71. videoPlayer.src = url;
  72. videoPlayer.addEventListener('canplay', function () {
  73. videoPlayer.play();
  74. });
  75. }
  76. window.closeVideoPopup = function () {
  77. videoPopup.style.display = 'none';
  78. videoPlayer.pause(); // 停止视频播放
  79. videoPlayer.src = ''; // 重置视频源,避免浏览器缓存问题
  80. };
  81. // 点击模态对话框外部时关闭对话框(可选,但推荐添加)
  82. videoPopup.addEventListener('click', function (event) {
  83. if (event.target === videoPopup) {
  84. closeVideoPopup();
  85. }
  86. });
  87. // 防止点击关闭按钮时事件冒泡到弹出层导致关闭(因为我们已经为关闭按钮单独绑定了事件)
  88. var closeButton = document.querySelector('.close');
  89. if (closeButton) {
  90. closeButton.addEventListener('click', function (event) {
  91. event.stopPropagation();
  92. });
  93. }
  94. }
  95. function generateVideoContent(video) {
  96. var div = document.getElementById('video-content');
  97. div.innerHTML = `
  98. <h1 style="font-size: 16pt; font-weight: bold;">${video.seoTitle}</h1>
  99. `;
  100. var contentHTML = '<div>';
  101. video.contents.forEach(item => {
  102. contentHTML += `
  103. <div class="image-card" style="margin-bottom: 10px;">
  104. <a href=${item.uri}><img src=${item.thumb} alt='${item.title}'></a>
  105. <div class="card-title">${item.title}</div>
  106. </div>
  107. `
  108. });
  109. contentHTML += '</div>';
  110. div.innerHTML += contentHTML;
  111. }
  112. </script>
  113. </body>
  114. </html>