hlsPlayback.js 997 B

123456789101112131415161718192021222324252627
  1. // @license http://www.gnu.org/licenses/agpl-3.0.html AGPL-3.0
  2. // SPDX-License-Identifier: AGPL-3.0-only
  3. function playVideo(overlay) {
  4. const video = overlay.parentElement.querySelector('video');
  5. const url = video.getAttribute("data-url");
  6. const startTime = parseFloat(video.getAttribute("data-start") || "0");
  7. video.setAttribute("controls", "");
  8. overlay.style.display = "none";
  9. if (Hls.isSupported()) {
  10. var hls = new Hls({autoStartLoad: false});
  11. hls.loadSource(url);
  12. hls.attachMedia(video);
  13. hls.on(Hls.Events.MANIFEST_PARSED, function () {
  14. hls.loadLevel = hls.levels.length - 1;
  15. hls.startLoad(startTime);
  16. video.play();
  17. });
  18. } else if (video.canPlayType('application/vnd.apple.mpegurl')) {
  19. video.src = url;
  20. video.addEventListener('canplay', function() {
  21. if (startTime > 0) video.currentTime = startTime;
  22. video.play();
  23. });
  24. }
  25. }
  26. // @license-end