videoJS播放rtmp流

引入相关文件

<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代码

同一个页面创建多个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();

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

猜你喜欢

转载自www.cnblogs.com/lmxHome/p/10856817.html