步骤

  1. 引入 video-js
  2. 定义一个 video 标签,源就直接填写 m3u8 路径好了
  3. 初始化,直接用

教程refer: GO video.js: GO

保存为HTML文件,双击打开即可播放。

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8" />
  5. <title>Video.js 7.4.1</title>
  6. <link href="https://vjs.zencdn.net/7.6.6/video-js.css" rel="stylesheet" />
  7. <style>
  8. body {
  9. background-color: #191919;
  10. }
  11. .m {
  12. width: 960px;
  13. height: 400px;
  14. margin-left: auto;
  15. margin-right: auto;
  16. margin-top: 100px;
  17. }
  18. </style>
  19. </head>
  20. <body>
  21. <div class="m">
  22. <video
  23. id="my-video"
  24. class="video-js"
  25. controls
  26. preload="auto"
  27. width="960"
  28. height="400"
  29. poster="m.jpg"
  30. data-setup="{}"
  31. >
  32. <source
  33. src="http://122.193.19.2:8088/1008-80d60cc3-6a5a-4e8d-b2c4-eae0bbe2d5c9/index.m3u8"
  34. type="application/x-mpegURL"
  35. />
  36. <!-- <source src="http://vjs.zencdn.net/v/oceans.webm" type="video/webm">
  37. <source src="http://vjs.zencdn.net/v/oceans.ogv" type="video/ogg"> -->
  38. <p class="vjs-no-js">
  39. To view this video please enable JavaScript, and consider upgrading to
  40. a web browser that
  41. <a href="http://videojs.com/html5-video-support/" target="_blank"
  42. >supports HTML5 video</a
  43. >
  44. </p>
  45. </video>
  46. <script src="https://vjs.zencdn.net/7.6.6/video.js"></script>
  47. <script type="text/javascript">
  48. //设置中文
  49. videojs.addLanguage("zh-CN", {
  50. Play: "播放",
  51. Pause: "暂停",
  52. "Current Time": "当前时间",
  53. Duration: "时长",
  54. "Remaining Time": "剩余时间",
  55. "Stream Type": "媒体流类型",
  56. LIVE: "直播",
  57. Loaded: "加载完毕",
  58. Progress: "进度",
  59. Fullscreen: "全屏",
  60. "Non-Fullscreen": "退出全屏",
  61. Mute: "静音",
  62. Unmute: "取消静音",
  63. "Playback Rate": "播放速度",
  64. Subtitles: "字幕",
  65. "subtitles off": "关闭字幕",
  66. Captions: "内嵌字幕",
  67. "captions off": "关闭内嵌字幕",
  68. Chapters: "节目段落",
  69. "Close Modal Dialog": "关闭弹窗",
  70. Descriptions: "描述",
  71. "descriptions off": "关闭描述",
  72. "Audio Track": "音轨",
  73. "You aborted the media playback": "视频播放被终止",
  74. "A network error caused the media download to fail part-way.":
  75. "网络错误导致视频下载中途失败。",
  76. "The media could not be loaded, either because the server or network failed or because the format is not supported.":
  77. "视频因格式不支持或者服务器或网络的问题无法加载。",
  78. "The media playback was aborted due to a corruption problem or because the media used features your browser did not support.":
  79. "由于视频文件损坏或是该视频使用了你的浏览器不支持的功能,播放终止。",
  80. "No compatible source was found for this media.":
  81. "无法找到此视频兼容的源。",
  82. "The media is encrypted and we do not have the keys to decrypt it.":
  83. "视频已加密,无法解密。",
  84. "Play Video": "播放视频",
  85. Close: "关闭",
  86. "Modal Window": "弹窗",
  87. "This is a modal window": "这是一个弹窗",
  88. "This modal can be closed by pressing the Escape key or activating the close button.":
  89. "可以按ESC按键或启用关闭按钮来关闭此弹窗。",
  90. ", opens captions settings dialog": ", 开启标题设置弹窗",
  91. ", opens subtitles settings dialog": ", 开启字幕设置弹窗",
  92. ", opens descriptions settings dialog": ", 开启描述设置弹窗",
  93. ", selected": ", 选择",
  94. "captions settings": "字幕设定",
  95. "Audio Player": "音频播放器",
  96. "Video Player": "视频播放器",
  97. Replay: "重播",
  98. "Progress Bar": "进度小节",
  99. "Volume Level": "音量",
  100. "subtitles settings": "字幕设定",
  101. "descriptions settings": "描述设定",
  102. Text: "文字",
  103. White: "白",
  104. Black: "黑",
  105. Red: "红",
  106. Green: "绿",
  107. Blue: "蓝",
  108. Yellow: "黄",
  109. Magenta: "紫红",
  110. Cyan: "青",
  111. Background: "背景",
  112. Window: "视窗",
  113. Transparent: "透明",
  114. "Semi-Transparent": "半透明",
  115. Opaque: "不透明",
  116. "Font Size": "字体尺寸",
  117. "Text Edge Style": "字体边缘样式",
  118. None: "无",
  119. Raised: "浮雕",
  120. Depressed: "压低",
  121. Uniform: "均匀",
  122. Dropshadow: "下阴影",
  123. "Font Family": "字体库",
  124. "Proportional Sans-Serif": "比例无细体",
  125. "Monospace Sans-Serif": "单间隔无细体",
  126. "Proportional Serif": "比例细体",
  127. "Monospace Serif": "单间隔细体",
  128. Casual: "舒适",
  129. Script: "手写体",
  130. "Small Caps": "小型大写字体",
  131. Reset: "重启",
  132. "restore all settings to the default values": "恢复全部设定至预设值",
  133. Done: "完成",
  134. "Caption Settings Dialog": "字幕设定视窗",
  135. "Beginning of dialog window. Escape will cancel and close the window.":
  136. "开始对话视窗。离开会取消及关闭视窗",
  137. "End of dialog window.": "结束对话视窗"
  138. });
  139. var myPlayer = videojs("my-video");
  140. videojs("my-video").ready(function() {
  141. var myPlayer = this;
  142. myPlayer.play();
  143. });
  144. </script>
  145. </div>
  146. </body>
  147. </html>