npm构建装依赖
flvjs中文文档,谢谢博主提供,地址为:点击此地址
网上我也找到一个,不知道哪个兄弟放上去的 http://1011.hlsplay.aodianyun.com/demo/game.flv 谢谢此兄弟。
拿到上面的地址,可以在npm官网搜索flv.js 如图: 1.步骤一 2.步骤二
<template>
<div class="videoGroup">
<video :id="flvInfo.id" controls muted width="100%" height="100%" class="flvVideo"></video>
</div>
</template>
<script>
import flvjs from 'flv.js'
export default {
components:{
VideoTitle
},
props:{
flvInfo:{
type:Object,
default:()=>{
return {}
}
}
},
data(){
return {
flvPlayer:null,
changeLampPost:false,
}
},
created(){},
mounted(){
this.init();
},
methods:{
init(){
let _this = this;
if (flvjs.isSupported()) {
var videoElement = document.getElementById(this.flvId);
this.flvPlayer = flvjs.createPlayer({
type: 'flv',
isLive: true,
hasAudio: false,
stashInitialSize: 128,
url: this.flvInfo.url
});
this.flvPlayer.attachMediaElement(videoElement);
try{
setTimeout(function() {
_this.flvPlayer.load();
if(_this.flvPlayer.play() !== undefined){
_this.flvPlayer.play().then(()=>{
_this.flvPlayer.play()
}).catch(()=>{
console.error("突然暂停了")
})
}
}, 500);
}catch(err){
console.error("flv组件播放时报错",err)
}
this.flvPlayer.on(flvjs.Events.STATISTICS_INFO, (res) => {
if (_this.changeLampPost) {
_this.flvPlayer.pause();
_this.flvPlayer.unload();
_this.flvPlayer.detachMediaElement();
_this.flvPlayer.destroy();
_this.flvPlayer= null;
}
})
}
},
},
destroyed(){
let _this = this
setTimeout(() => {
_this.flvPlayer.pause()
_this.changeLampPost = true;
},500)
},
watch:{}
}
</script>
<style lang="less" scoped>
.videoGroup{
width:100%;
height:100%;
position:relative;
overflow: hidden;
}
.videoGroup:hover .vg_title{
top:0px;
}
.flv_box{
width: 100%;
height: 100vh;
}
.flvVideo{ //视频撑满
object-fit: fill;
}
</style>
|