使用videojs连续播放m3u8格式的视频

实习遇到的问题,记录:

<!DOCTYPE html>
<html xmlns:th="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/1999/html">
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="/css/video-js.css" />
    <script type="text/javascript" src="/js/video.min.js"></script>
    <script type="text/javascript" src="/js/videojs-contrib-hls.js"></script>
</head>
<body>
<div id="shipin">
    <div id="video" style="width:900px;height:500px;margin-top:20px;margin-left: 20px;">
        <video id="example_video_1" class="video-js vjs-default-skin" controls preload="none"  data-setup="{}" height=500px width=900px>
        </video>
    </div>
    <input type="text" style="display:none"id="vid" th:value="${videoArray}">
</div>
</body>
<script>

       var url = document.getElementById("vid").value;
       var vList = url.split(",");// 初始化播放列表
    var vLen = vList.length;
    var curr = vLen-1;//因为取路径的时候是倒序,所以选择从后向前播
    var video = document.getElementById("example_video_1");
    var options = {
        controls: true,
        preload: 'auto',
        loop: false, //注意:此地方一定要设置为false,不然会循环播放同一个视频

    };
    var player = videojs('example_video_1', options, function onPlayerReady() {
        play();
        video.addEventListener('ended', function(){
            play();
        });
    });

    function play() {
        player.src({
            src: vList[curr],
            type: 'application/x-mpegURL'//在重新添加视频源的时候需要给新的type的值
        })
        video.load();
        video.play();
        curr--;
        if(curr < 0){
            curr = vLen-1 ; //重新循环播放
        }

    }

</script>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值