视频监控hls.js用法

在这里插入图片描述
在这里插入图片描述
加载错误解决方法

<div class="x-flex-item">
	<div class="video-item success">
		<video id="live" rtmpPath="http://spjk.xrwhcm.cn/live/44020000001320000093.m3u8?auth_key=1645764049-0-0-107386e412fb4467aed32ef4b779b556yes" type="application/x-mpegURL" muted></video>
		<!-- 监控名称 -->
		<div class="x-video-title">隧道出口洞口</div>
		<!-- 提示信息 -->
		<div class="video-tips"></div>
	</div>
</div>
var hls = null;
function fnCameraPlayer(id){  
  var video = document.getElementById(id);
  var videoSrc = video.getAttribute('rtmpPath');
  // First check for native browser HLS support
  if (video.canPlayType('application/vnd.apple.mpegurl') || video.canPlayType('application/x-mpegURL')) {
    video.src = videoSrc;
    video.addEventListener('loadedmetadata', function() {
      console.log("manifest loaded, found " + data.levels.length + " quality level",videoSrc);
      $('#'+ id).closest('.video-item').addClass('success');
      video.play();
    });
  // If no native HLS support, check if hls.js is supported
  } else if (Hls.isSupported()) {
    hls = new Hls();
    hls.loadSource(videoSrc);
    hls.attachMedia(video);
    hls.on(Hls.Events.MANIFEST_PARSED, function(event, data) {
      console.log("manifest loaded, found " + data.levels.length + " quality level",videoSrc);
      $('#'+ id).closest('.video-item').addClass('success');
      video.play();
    });
    hls.on(Hls.Events.ERROR, function (event, data) {
      if (data.fatal) {  
        $('#'+ id).siblings('.video-tips').text('设备离线');
        $('#'+ id).closest('.video-item').addClass('error').removeClass('success');      
        switch(data.type) {
        case Hls.ErrorTypes.NETWORK_ERROR:
        // try to recover network error        
          console.log("fatal network error encountered, try to recover",videoSrc);  
          if (data.details === Hls.ErrorDetails.MANIFEST_LOAD_ERROR || data.details === Hls.ErrorDetails.MANIFEST_LOAD_TIMEOUT || data.details === Hls.ErrorDetails.MANIFEST_PARSING_ERROR) {
            hls.loadSource(videoSrc)
          }
          else {
            hls.startLoad()
          }
          break;
        case Hls.ErrorTypes.MEDIA_ERROR: 
          console.log("fatal media error encountered, try to recover",videoSrc);    
          hls.recoverMediaError();
          break;
        default:
        // cannot recover
          hls.destroy();
          break;
        }
      }      
    });
  }
}

在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值