video标签播放m3u8格式视频

直接使用video.js插件就行了
video插件用法:https://www.awaimai.com/2053.html

< !DOCTYPE html>
< html lang=“zh-CN”>
< head>
< meta charset=“UTF-8”>
< title>前端播放m3u8格式视频
< link href=“https://vjs.zencdn.net/7.4.1/video-js.css” rel=“stylesheet”>
< script src=‘https://vjs.zencdn.net/7.4.1/video.js’>
< script src=“https://cdnjs.cloudflare.com/ajax/libs/videojs-contrib-hls/5.15.0/videojs-contrib-hls.min.js” type=“text/javascript”>
< !-- videojs-contrib-hls 用于在电脑端播放 如果只需手机播放可以不引入 -->
< /head>
< body>
< style>
.video-js .vjs-tech {position: relative !important;}
< /style>
< div>
< video id=“myVideo” class=“video-js vjs-default-skin vjs-big-play-centered” controls preload=“auto” data-setup=’{}’ style=‘width: 100%;height: auto’>
< source id=“source” src=“http://1252093142.vod2.myqcloud.com/4704461fvodcq1252093142/48c8a9475285890781000441992/playlist.m3u8” type=“application/x-mpegURL”>
< /video>
< /div>
< div class=“qiehuan” style=“width:100px;height: 100px;background: red;margin:0 auto;line-height: 100px;color:#fff;text-align: center”>切换视频
< /body>

< script>
// videojs 简单使用
var myVideo = videojs(‘myVideo’, {
bigPlayButton: true,
textTrackDisplay: false,
posterImage: false,
errorDisplay: false,
})
myVideo.play()
var changeVideo = function (vdoSrc) {
if (/.m3u8$/.test(vdoSrc)) { //判断视频源是否是m3u8的格式
myVideo.src({
src: vdoSrc,
type: ‘application/x-mpegURL’ //在重新添加视频源的时候需要给新的type的值
})
} else {
myVideo.src(vdoSrc)
}
myVideo.load();
myVideo.play();
}
var src = ‘http://1252093142.vod2.myqcloud.com/4704461fvodcq1252093142/f865d8a05285890787810776469/playlist.f3.m3u8’;
document.querySelector(’.qiehuan’).addEventListener(‘click’, function () {
changeVideo(src);
})
< /script>

还有一种方法就是腾讯的TCPlayerLite,文档地址:https://cloud.tencent.com/document/product/881/20207

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值