提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
Vue 播放rtmp直播流
前言
该组件是在vue-video-player基础上封装,支持播放mp4/rtmp等格式一、vueVideo.vue封装
<template>
<div style="width:100%;height:100%" ref="videoContainer">
<video-player ref="myPlayer" :options="playerOptions" v-show="contianerW"></video-player>
</div>
</template>
<script>
import Vue from 'vue'
import VideoPlayer from 'vue-video-player'
import 'videojs-flash'
require('video.js/dist/video-js.css')
require('vue-video-player/src/custom-theme.css')
Vue.use(VideoPlayer)
export default {
components: {},
data() {
contianerW: 0
},
props: {
videoOptions: {
type: Object,
default: () => {
return {};
}
}
},
computed: {
playerOptions() {
return {
width: this.contianerW,
sources: [{
type: "rtmp/mp4",
src: this.videoOptions.sourceSrc || ``
}],
techOrder: ['flash'],
autoplay: true,
controls: false,
loop: false,
notSupportedMessage: `当前无可播放视频源`
}
}
},
mounted() {
this.contianerW = this.$refs.videoContainer.offsetWidth;
},
};
</script>
二、调用方式
...
....
<VueVideo :videoOptions="videoOptions"></VueVideo>
...
...
import VueVideo from "$pc/components/vueVideo";
components: {
VueVideo
},
....
....
data() {
return {
videoOptions: {
sourceType: 'video/mp4',
sourceSrc : '视频流地址'
},
};
},