引入相关文件

<link rel="stylesheet" type="text/css" href="http://vjs.zencdn.net/5.5.3/video-js.css"/>
<script src="http://vjs.zencdn.net/ie8/1.1.1/videojs-ie8.min.js"></script>
<script src="http://vjs.zencdn.net/5.5.3/video.js"></script>

html代码

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

同一个页面创建多个video时,id需要不同,否则报错。

let n = ""+Math.ceil(Math.random()*10)+Math.ceil(Math.random()*10)+Math.ceil(Math.random()*10);
<div id="container">
  `<video id="myVideo${n}" class="video-js" controls autoplay="true" preload="auto" data-setup="{}">
      <source src = "${rtmp_src}" type="rtmp/flv"></source>
  </video>`
</div>

js代码

设置自动播放

const _id = this.container.getElementsByTagName('video')[0].getAttribute("id");
let myPlayer = this.videojs(_id);
myPlayer.play();

 

以上代码不能直接复制运行,只做参考,需要自行修改。

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄