player.html 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>hls.js Player</title>
  6. <script src="https://cdn.jsdelivr.net/npm/hls.js@latest"></script>
  7. <style>
  8. .container {
  9. width: 80%;
  10. margin: 0 auto;
  11. }
  12. .video-wrapper {
  13. padding-top: 20px;
  14. height: 80%;
  15. margin: 0 auto;
  16. }
  17. video {
  18. display: block;
  19. width: 100%;
  20. height: 100%;
  21. }
  22. </style>
  23. </head>
  24. <body>
  25. <div class="container">
  26. <h1>hls.js player</h1>
  27. <a href="https://github.com/video-dev/hls.js">github.com/video-dev/hls.js</a>
  28. <div class="video-wrapper">
  29. <video id="video" controls muted></video>
  30. </div>
  31. </div>
  32. <script>
  33. var params = new URLSearchParams(window.location.search);
  34. var url = params.get('url');
  35. if (Hls.isSupported()) {
  36. var video = document.getElementById('video');
  37. var hls = new Hls();
  38. hls.attachMedia(video);
  39. hls.on(Hls.Events.MEDIA_ATTACHED, function () {
  40. hls.loadSource(url);
  41. hls.on(Hls.Events.MANIFEST_PARSED, function (event, data) {
  42. video.play();
  43. });
  44. });
  45. }
  46. </script>
  47. </body>
  48. </html>