vue使用B站开源播放器flv.js和原生video实现视频直播,播放
flv.js<template><div class="flv_box"><video id="myvideo" controlsautoplay muted></video><button @click="onClick()">播放</button><button @click="clickStop()">暂停&
·
flv.js
<template>
<div class="flv_box">
<video id="myvideo" controls autoplay muted></video>
<button @click="onClick()">播放</button>
<button @click="clickStop()">暂停</button>
</div>
</template>
<script>
import flv from 'flv.js';
export default {
name:'flv',
components:{},
data(){return{
player : null,
playing: false,
}},
created(){
if(flv.isSupported()){
this.player = flv.createPlayer({
// type: 'flv',
type: "video/mp4",
url:'xxxxxx' //获取视频播放资源路径
});
}
},
mounted()
{
var video = document.querySelector('#myvideo')
this.player.attachMediaElement(video)
this.player.load()
},
methods:{
onClick(){
console.log('播放')
this.player.play()
this.playing = true;
},
clickStop(){
console.log('暂停')
this.player.pause()
this.playing = false;
}
}
}
</script>
<style lang="scss" scoped>
.flv_box{
width: 100%;
height: 100vh;
#myvideo{
width: 100%;
height: 400px;
}
}
</style>
video
<template>
<div class="box">
<div v-on:click="playVideo()">
<video :src="videoSrc" controls id="videoPlay" v-show="true" class="video">您的浏览器不支持 video 视屏播放。</video>
</div>
</div>
</template>
<script>
export default {
name:'videoList',
components: {},
data() {
return {
videoSrc: "xxxxxxxx", //获取视频播放资源路径
};
},
created() {},
computed: {},
methods: {
playVideo() {
console.log('播放')
var vdo = document.getElementById("videoPlay");
vdo.play();
console.log(vdo)
console.log(this)
},
},
};
</script>
<style lang="scss" scoped>
.box {
width: 100%;
height: 100vh;
video{
width: 100%;
height: 400px;
}
}
</style>
更多推荐
已为社区贡献3条内容
所有评论(0)