下载flv.js
cnpm install flv.js
引入
import flvjs from 'flv.js'
使用
HTML
<video ref="videoElement" v-model="test" id="dplayer" controls autoplay muted width="600" height="450"></video>
JS
let video = document.getElementById("dplayer"); //绑定dom(ref或id都可)
if (flvjs.isSupported()) {
this.player = flvjs.createPlayer({
type: "flv", // 定义格式
url: res2.data.videoAddress, // 播放路径
});
} else {
this.$message.error("不支持的格式");
return;
}
this.player.attachMediaElement(video);
this.player.load();
this.player.play(); // 打开
if (this.player) { // 关闭
this.player.pause();
this.player.destroy();
this.player = null;
}