是否有限制HLS m3u8播放列表播放范围的开源实现?
我可以使用
hls.js
库,指定视频的开始时间并施加持续时间以标识结束时间。我的目标是限制m3u8播放列表的播放范围,因为我会让用户想要查看大约3-5小时视频播放列表中8-15秒的特定片段。我不希望我的用户能够在整个视频播放列表中搜索,只是预先指定的播放范围。
因此,例如,如果我指定的剪辑从00:02:30(2分30秒)开始,到00:02:40(2分40秒)结束,持续时间为10秒,我如何将视频播放器的播放范围设置为00:00:00到00:00:10?
index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>HLS Demo</title>
<link rel="stylesheet" href="https://cdn.plyr.io/1.8.2/plyr.css">
</head>
<body style="width: 40%; height: 40%">
<video preload="none" id="player" autoplay controls crossorigin></video>
<script src="https://cdn.plyr.io/1.8.2/plyr.js"></script>
<script src="https://cdn.jsdelivr.net/hls.js/latest/hls.js"></script>
<script src="./script.js"></script>
</body>
</html>
myscript.js
(function () {
var video = document.querySelector('#player');
if (Hls.isSupported()) {
// ALL CONFIG OPTIONS HERE: https://github.com/video-dev/hls.js/blob/master/docs/API.md
var config = {
autoStartLoad: true,
startPosition: 150, // 00:02:30 IN SECONDS
debug: false
};
var hls = new Hls(config);
hls.loadSource('https://bitdash-a.akamaihd.net/content/MI201109210084_1/m3u8s/f08e80da-bf1d-4e3d-8899-f0f6155f6efa.m3u8');
hls.attachMedia(video);
// hls.on(Hls.Events.MEDIA_ATTACHED, function() {
hls.on(Hls.Events.MANIFEST_PARSED,function() {
video.muted = true;
video.play();
setTimeout(function(){
video.pause();
}, 10000);
});
}
plyr.setup(video);
})();
CodePen可用
here
.
我要实现的功能或多或少都有描述
here
,我只是很惊讶这不是更简单,除非我忽略了一些明显的东西。
提前感谢。