video-story-section.ejs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <script src="https://cdn.jsdelivr.net/npm/hls.js@latest"></script>
  2. <div class="content-wrapper">
  3. <div class="content-title">
  4. <h2>
  5. <%= translate.videoStories[lang] %>:
  6. </h2>
  7. <a href="<%= lang %>/videos">
  8. <%= translate.more[lang] %> >>>
  9. </a>
  10. </div>
  11. <div class="content">
  12. <div class="album-icon-grid">
  13. <% videos.forEach(video=> { %>
  14. <div class="album-grid-card">
  15. <div style="padding: 2px; font-size: 14px; color: grey; text-align: center; white-space: nowrap;">
  16. <%= translate.videoStory[lang] %>
  17. </div>
  18. <a href="javascript:;" onclick="onPlay('<%= video.url %>')">
  19. <img src="<%= video.poster %>" class="album-icon-img" alt="<%= video.seoTitle %>">
  20. <img src="/assets/svg/play-button.svg" , class="play-button" width="20px" height="20px"
  21. alt="Coloring Page Video Play Button">
  22. </a>
  23. <!-- <video id="video" controls>
  24. <source src="<%= video.url %>" type="application/x-mpegURL">
  25. </video> -->
  26. </div>
  27. <% }); %>
  28. </div>
  29. </div>
  30. </div>
  31. <!-- 弹出层 -->
  32. <div id="video-popup" class="popup">
  33. <div class="popup-content">
  34. <span class="close" onclick="closeVideoPopup()">&times;</span>
  35. <video id="video-player" width="400" height="500" controls></video>
  36. </div>
  37. </div>
  38. <script>
  39. function onPlay(url) {
  40. var videoPopup = document.getElementById('video-popup');
  41. var videoPlayer = document.getElementById('video-player');
  42. videoPopup.style.display = 'block';
  43. if (Hls.isSupported()) {
  44. var hls = new Hls();
  45. hls.loadSource(url);
  46. hls.attachMedia(videoPlayer);
  47. hls.on(Hls.Events.MANIFEST_PARSED, function () {
  48. videoPlayer.play();
  49. });
  50. } else if (videoPlayer.canPlayType('application/vnd.apple.mpegurl')) {
  51. videoPlayer.src = url;
  52. videoPlayer.addEventListener('canplay', function () {
  53. videoPlayer.play();
  54. });
  55. }
  56. window.closeVideoPopup = function () {
  57. videoPopup.style.display = 'none';
  58. videoPlayer.pause(); // 停止视频播放
  59. videoPlayer.src = ''; // 重置视频源,避免浏览器缓存问题
  60. };
  61. // 点击模态对话框外部时关闭对话框(可选,但推荐添加)
  62. videoPopup.addEventListener('click', function (event) {
  63. if (event.target === videoPopup) {
  64. closeVideoPopup();
  65. }
  66. });
  67. // 防止点击关闭按钮时事件冒泡到弹出层导致关闭(因为我们已经为关闭按钮单独绑定了事件)
  68. var closeButton = document.querySelector('.close');
  69. if (closeButton) {
  70. closeButton.addEventListener('click', function (event) {
  71. event.stopPropagation();
  72. });
  73. }
  74. }
  75. </script>