- npm install --save flv.js
- 引用import flvjs from “flv.js/dist/flv.min.js”;`
data(){
return{
wrjzhData:{
attachmentName: "https://api.tjdataspace.com/flv.flv",
fileName: "航拍视频",videoType:"flv",
id: 3
}
}
}
mounted(){
this.playZhPause(this.wrjzhData)
}
methods:{
playZhPause(row){
if (flvjs.isSupported()) {
this.flvPlayer = flvjs.createPlayer(
{
type: row.videoType,
isLive: true,
hasAudio: false,
url: row.attachmentName,
}
// {
// cors: true, // 是否跨域
// enableWorker: true, // 是否多线程工作
// enableStashBuffer: false, // 是否启用缓存
// stashInitialSize: 128, // 缓存大小(kb) 默认384kb
// autoCleanupSourceBuffer: true // 是否自动清理缓存
// }
);
this.$nextTick(() => {
this.playZhVideo();
});
}
},
playZhVideo(){
let videoElement = this.$refs.zhFlvVideo;
this.flvPlayer.attachMediaElement(videoElement);
this.flvPlayer.load();
this.flvPlayer.play();
// 报错重连
this.flvPlayer.on(flvjs.Events.ERROR, (errType, errDetail) => {
if (this.flvPlayer) {
this.destoryVideo();
this.createVideo();
}
});
},
destoryZhVideo() {
this.iswrj = false;
if (this.flvPlayer) {
this.flvPlayer.pause();
this.flvPlayer.unload();
this.flvPlayer.detachMediaElement();
this.flvPlayer.destroy();
this.flvPlayer = null;
}
}
}