hlsPlayback.js 1.1 KB

123456789101112131415161718192021222324252627282930
  1. // @license http://www.gnu.org/licenses/agpl-3.0.html AGPL-3.0
  2. // SPDX-License-Identifier: AGPL-3.0-only
  3. function playMedia(overlay, tagName) {
  4. const media = overlay.parentElement.querySelector(tagName);
  5. const url = media.getAttribute("data-url");
  6. const startTime = parseFloat(media.getAttribute("data-start") || "0");
  7. media.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(media);
  13. hls.on(Hls.Events.MANIFEST_PARSED, function () {
  14. hls.loadLevel = hls.levels.length - 1;
  15. hls.startLoad(startTime);
  16. media.play();
  17. });
  18. } else if (media.canPlayType('application/vnd.apple.mpegurl')) {
  19. media.src = url;
  20. media.addEventListener('canplay', function() {
  21. if (startTime > 0) media.currentTime = startTime;
  22. media.play();
  23. });
  24. }
  25. }
  26. function playVideo(overlay) { playMedia(overlay, 'video'); }
  27. function playAudio(overlay) { playMedia(overlay, 'audio'); }
  28. // @license-end