1. npm安装flv.js
npm install flv.js
2. 项目引入flv.js
import flvjs from "flv.js";
3. 简单使用flv.js
//template
<video
id="videoElement"
ref="videoElement"
controls
muted
width="100%"
height="100%"
></video>
//script
data() {
return {
flvPlayer: null
}
},
methods: {
//创建flv视频实例
createFlv() {
let url="http://xxxxxxxx.flv";
if (flvjs.isSupported()) {
let videoElement = document.getElementById("videoElement");
this.flvPlayer = flvjs.createPlayer({
type: "flv",
isLive: true,
hasAudio: false,
url
});
this.flvPlayer.attachMediaElement(videoElement);
this.flvPlayer.load();
}
}
}
4.销毁flv实例
//销毁flv实例
flv_destroy() {
if (this.flvPlayer) {
this.flvPlayer.pause();
this.flvPlayer.unload();
this.flvPlayer.detachMediaElement();
this.flvPlayer.destroy();
this.flvPlayer = null;
}
}
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。