zoukankan      html  css  js  c++  java
  • hls视频播放-web视频播放

    由于非Safari浏览器不能直接支持hls视频播放,使用Html5的video标签嵌入视频文件进行播放,由于video标签只支持MP4、WebM、Ogg等格式,

    无法加载hls的m3u8格式文件,不能用在chrome,ie等浏览器上。

     基于ChPlayer 视频播放

    经过查询资料发现ChPlayer,使用ChPlayer进行视频的播放,支持点播和直播,支持m3u8格式。

    调用示例:

    <script type="text/javascript">
       var videoObject = {
           logo: 'chplayer', //设置logo,非必须
           container: '#video',//“#”代表容器的ID,“.”或“”代表容器的class
           variable: 'player',//该属性必需设置,值等于下面的new chplayer()的对象
           video:'examples01.mp4'//视频地址
       };
       var player=new chplayer(videoObject);
    </script>

     基于hls.js 视频播放

    html5浏览器实现hls视频播放的兼容解决方案hls.js。兼容IE8/IE11/edge/Chrome/火狐。

    github传送门:https://github.com/video-dev/hls.js 

    官方示例:

    <script src="https://cdn.jsdelivr.net/npm/hls.js@latest"></script>
    <!-- Or if you want a more recent canary version -->
    <!-- <script src="https://cdn.jsdelivr.net/npm/hls.js@canary"></script> -->
    <video id="video"></video>
    <script>
      var video = document.getElementById('video');
      if(Hls.isSupported()) {
        var hls = new Hls();
        hls.loadSource('https://video-dev.github.io/streams/x36xhzz/x36xhzz.m3u8');
        hls.attachMedia(video);
        hls.on(Hls.Events.MANIFEST_PARSED,function() {
          video.play();
      });
     }
     // hls.js is not supported on platforms that do not have Media Source Extensions (MSE) enabled.
     // When the browser has built-in HLS support (check using `canPlayType`), we can provide an HLS manifest (i.e. .m3u8 URL) directly to the video element throught the `src` property.
     // This is using the built-in support of the plain video element, without using hls.js.
     // Note: it would be more normal to wait on the 'canplay' event below however on Safari (where you are most likely to find built-in HLS support) the video.src URL must be on the user-driven
     // white-list before a 'canplay' event will be emitted; the last video event that can be reliably listened-for when the URL is not on the white-list is 'loadedmetadata'.
      else if (video.canPlayType('application/vnd.apple.mpegurl')) {
        video.src = 'https://video-dev.github.io/streams/x36xhzz/x36xhzz.m3u8';
        video.addEventListener('loadedmetadata',function() {
          video.play();
        });
      }
    </script>
  • 相关阅读:
    linux 学习之七-部分ssh命令
    揭秘淘宝286亿海量图片存储与处理架构
    大型网站后台架构的演变
    Linux学习之六-Yum命令的使用
    res://ieframe.dll/acr_error.htm 纯手动解决方法
    VS2013启动项目调试的时候会启动本地IIS
    linux学习之(六)-主机名、网络IP的配置与查看
    deployment.yaml 带同步时区
    Deployment
    mysql.yaml
  • 原文地址:https://www.cnblogs.com/dpwow/p/9592302.html
Copyright © 2011-2022 走看看