hls.html 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>播放m3u8格式</title>
  6. <link href="https://unpkg.com/video.js/dist/video-js.css" rel="stylesheet">
  7. <script src="https://unpkg.com/video.js/dist/video.js"></script>
  8. <script src="https://unpkg.com/videojs-contrib-hls/dist/videojs-contrib-hls.js"></script>
  9. <!-- videojs-contrib-hls 用于在电脑端播放 如果只需移动端播放可以不引入 -->
  10. </head>
  11. <body>
  12. <style>
  13. .video-js .vjs-tech {position: relative !important;}
  14. </style>
  15. <div>
  16. <video id="myVideo" class="video-js vjs-default-skin vjs-big-play-centered" controls preload="auto" data-setup='{}'
  17. style='width: 100%;height: auto'>
  18. <source id="source" src="http://192.168.1.100:9996/rtp/06516E8D/hls.m3u8" type="application/x-mpegURL">
  19. </source>
  20. </video>
  21. </div>
  22. </body>
  23. <script>
  24. var myVideo = videojs('myVideo', {
  25. bigPlayButton: true,
  26. textTrackDisplay: false,
  27. posterImage: false,
  28. errorDisplay: false,
  29. })
  30. myVideo.play()
  31. var changeVideo = function(vdoSrc) {
  32. if (/\.m3u8$/.test(vdoSrc)) {
  33. myVideo.src({
  34. src: vdoSrc,
  35. type: 'application/x-mpegURL'
  36. })
  37. } else {
  38. myVideo.src(vdoSrc)
  39. }
  40. myVideo.load();
  41. myVideo.play();
  42. }
  43. </script>