当前位置:首页 > 技术分享

videojs前端播放m3u8格式视频

admin2年前 (2024-04-30)技术分享4601
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>前端播放m3u8格式视频</title>
    <link href="https://cdn.jsdelivr.net/npm/video.js@7.8.3/dist/video-js.min.css" rel="stylesheet">
    <script src='https://cdn.jsdelivr.net/npm/video.js@7.8.3/dist/video.min.js'></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/videojs-contrib-hls/5.15.0/videojs-contrib-hls.min.js" type="text/javascript"></script>
    <!-- 
    videojs-contrib-hls 用于在电脑端播放 如果只需手机播放可以不引入
    https://blog.csdn.net/u014696856/article/details/135365211
     -->
</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="https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8" type="application/x-mpegURL"></source>
        </video>
    </div>
    <div style="width:100px;height: 100px;background: red;margin:0 auto;line-height: 100px;color:#fff;text-align: center">切换视频</div>
</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 = 'https://test-streams.mux.dev/x36xhzz/x36xhzz.m3u8';
    document.querySelector('.qiehuan').addEventListener('click', function () {
        changeVideo(src);
    })
</script></html>


扫描二维码推送至手机访问。

版权声明:本文由小刚刚技术博客发布,如需转载请注明出处。

本文链接:https://blog.bitefu.net/post/591.html

分享给朋友:

“videojs前端播放m3u8格式视频” 的相关文章

解决 SVN Skipped 'xxx' -- Node remains in conflict

更新命令:svn up提示代码:意思就是说 ,这个文件冲突了,你要解决下Updating '.': Skipped 'data/config.php' -- …

微软版Ghost Win10:FFU映像备份和还原

微软版Ghost Win10:FFU映像备份和还原

在日常的维护中,系统的备份和还原是大家经常需要操作的事情。虽然Windows 10已经提供很多的工具,如系统还原、WIM备份/还原,VHD备份等。不过这些工具大多是基于文件的备份/还原。我们以前经常的使用的Ghost则是基于扇区的备份/还原…

PHP AES加解密 (ECB模式/sha1prng算法/PKCS5Padding和PKCS7Padding补码) ECB 模式不需求设置 iv

php7+ 版本/**  * [AesSecurity aes加密,支持PHP7+]  * 算法模式:ECB  * 密钥长度:128  * 补…

php Aes 加密模式ECB填充pkcs5padding base64

最近做支付项目用到了aes加密不过试了好多办法总是和官方给出的结果不一样,找了很久终于找到了测试结果同 http://tool.chacuo.net/cryptaes/ <?php /**  * [Aes&nb…

在CentOS 5.x 6.x里使用yum源 换阿里云国内源换vault.centos.org源

阿里云CentOS 5 的系统,无法用yum来安装应用软件。  原因:CentOS 5 在2017-03-31日已经结束支持,不再提供维护更新,所以包括阿里云镜像站的文件可能都是过时或已经有部分文件缺失。 &n…

Chrome 最全历史版本下载以及chromedriver下载

https://vikyd.github.io/download-chromium-history-version/#/ https://dl.lancdn.com/landian/soft/chrome/m/ chromedriver的版…

发表评论

访客

看不清,换一张

◎欢迎参与讨论,请在这里发表您的看法和观点。