vue-video-player播放 hls(m3u8)视频流

一、组件封装

<template>
    <div style="width:100%;height:100%;" ref="videoContainer">
        <video-player 
           class="video-js vjs-big-play-centered"
           ref="myPlayer" 
           :options="playerOptions" 
           v-show="contianerW"
           id="videoPlayer"
           :info="info"
        >
        </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);
import 'videojs-contrib-hls';

export default {
    components: {},
    data() {
       return {
        contianerW: 0,
        info : {}
       }
    },
    props: {
        videoOptions: {
            type: Object,
            default: () => {
                return {};
            }
        }
    },
    computed: {
        playerOptions() {
            return {
                width : this.contianerW,
                height : this.videoOptions.videoHeight || 'auto',
                sources: [{
                    withCredentials: false,
                    type: this.videoOptions.sourceType || `application/x-mpegURL`,
                    src: this.videoOptions.sourceSrc || ``
                }],
                autoplay: true,
                controlBar: {
                    timeDivider: false,
                    durationDisplay: false
                },
                flash: { hls: { withCredentials: false }},
                html5: { hls: { withCredentials: false }},
                loop: false,
                notSupportedMessage: `当前无可播放视频源`
            }
        }
    },
    activated() {
    },
    deactivated() {
        this.$destroy('VideoPlayer');
    },
    mounted() {
        this.contianerW = this.$refs.videoContainer.offsetWidth;
    },
    methods : {
    }
};
</script>

二、调用方式

代码如下(示例):

import VueVideo from "$pc/components/vueVideo/index.vue";
...
...
<VueVideo :videoOptions="videoOptions"></VueVideo>

...
...

data() {
     return {
         loading: false,
         videoOptions: {
             sourceType: 'application/x-mpegURL',
             sourceSrc: 'http://ivi.bupt.edu.cn/hls/cctv1hd.m3u8',
             videoHeight : 160,
             loop : false
         },
     };
 },
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值