video.js播放m3u8
时间: 2023-08-31 22:10:48 浏览: 55
video.js 是一个流行的 HTML5 视频播放器,它支持播放多种视频格式,包括 m3u8。要在 video.js 中播放 m3u8 文件,需要使用 video.js-contrib-hls 插件。
以下是一个基本的 HTML 示例代码,演示如何使用 video.js 播放 m3u8 文件:
```
<!DOCTYPE html>
<html>
<head>
<title>Video.js HLS Example</title>
<link rel="stylesheet" href="https://unpkg.com/video.js/dist/video-js.css" />
<script src="https://unpkg.com/video.js/dist/video.js"></script>
<script src="https://unpkg.com/videojs-contrib-hls/dist/videojs-contrib-hls.js"></script>
</head>
<body>
<video id="my-video" class="video-js" controls preload="auto" width="640" height="264"
poster="MY_VIDEO_POSTER.jpg" data-setup="{}">
<source src="path/to/my-video.m3u8" type="application/x-mpegURL">
<p class="vjs-no-js">
To view this video please enable JavaScript, and consider upgrading to a web browser that
<a href="https://videojs.com/html5-video-support/" target="_blank">supports HTML5 video</a>
</p>
</video>
</body>
</html>
```
在这个示例中,我们通过引用 video.js 和 videojs-contrib-hls 插件的 CDN 来加载它们。然后,在 video 元素中,我们指定了 m3u8 文件的 URL。这将告诉 video.js 使用 HLS 播放器来播放 m3u8 文件。
注意,在某些情况下,可能需要在服务器上配置 MIME 类型才能正确播放 m3u8 文件。如果您遇到问题,请检查服务器配置。