您好,在搜索了很多页面后,我找到了答案。在 videojs 7.xx 之后,dvrseekbar 插件功能被添加到 videojs。您不必为此下载或导入额外的插件。
这里解释https://github.com/videojs/video.js/blob/master/docs/guides/live.md
新用户界面目前可选择加入,以防止破坏向后兼容性。我们认为新的用户界面要好得多,它很可能会成为下一个主要版本的新默认设置。如果您想使用新的用户界面,您必须在播放器设置期间传递 {liveui: true}。这可以通过两种方式完成:
使用数据设置
使用videojs函数
var player = videojs('some-player-id', {liveui: true});
新的用户界面在控制栏上显示 ProgressControl 组件,隐藏 LiveDisplay 组件,并在 Video.js 检测到正在播放的视频是实时的(通过 durationchange 事件)时显示新的 SeekToLive 组件。除了 ProgressControl 更新,我们还更新了播放器上的所有时间工具提示,以指示当前时间的负数,而不是寻找特定时间。
这是一个简单的例子:
<link href="../dist/video-js.css" rel="stylesheet" type="text/css">
<script src="../dist/video.js"></script>
<script>
<video-js id="vid1" controls preload="auto" width="640" height="264">
<source src="https://akamai-axtest.akamaized.net/routes/lapd-v1-acceptance/www_c4/Manifest.m3u8" type="application/x-mpegURL">
</video-js>
<script>
var vid = document.getElementById('vid1');
var liveui = true
if (videojs.browser.IS_ANDROID) {
liveui = false;
}
var player = videojs(vid, {liveui: liveui});
</script>
但是,当我尝试时,我遇到了很多问题,但它没有正常工作。我还必须对 css 文件进行一些更改。
但是,我发现了一个完美的 liveui 功能示例。你可以在这里查看https://codepen.io/facundofernandez/pen/LmLPVW。这是该示例的代码。
<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<title>Videojs 7.5 liveui</title>
<link rel='stylesheet' href='https://unpkg.com/video.js@7.5.0/dist/video-js.min.css'>
</head>
<body>
<div class="container">
<video id="my-video" class="video-js" controls preload="auto" width="870" height="364" ></video>
</div>
<script src='https://unpkg.com/video.js@7.5.0/dist/video.min.js'></script>
<script >
let hls = {
//src: 'https://d2zihajmogu5jn.cloudfront.net/bipbop-advanced/bipbop_16x9_variant.m3u8',
src:
"https://akamai-axtest.akamaized.net/routes/lapd-v1-acceptance/www_c4/Manifest.m3u8",
type: "application/x-mpegURL" };
let options = {
liveui: true,
//liveTracker: true,
userActions: {
hotkeys: function (event) {
console.log(event);
} } };
videojs.log.history.disable();
videojs.log.history.clear();
let readyPlayer = function () {
this.src(hls);
};
let player = videojs("my-video", options, readyPlayer);
console.log(player, player.liveTracker, player.liveTracker.startTracking());
player.on("error", e => {
console.log(
"error:",
player.error().MEDIA_ERR_SRC_NOT_SUPPORTED,
player.error().code,
player.error().message);
});
</script>
</body>
</html>