vue+tcplyer播放flv视频基础使用

dispose方法会摧毁dom 所以调用了之后 需要自己去生成一个dom,

<template>
    <div class="player">
        <div ref="video-outer" v-show="enableFlag" class="video-player-page">
            <!-- <video id="videoDom" class="video"></video> -->
        </div>
        <img v-show="!enableFlag" src="../../../../public/images/no-single.png" alt="">
    </div>

</template>
<script>
    export default {
        props: ['src','enableFlag'],
        data() {
            return {
                player: null,
            }
        },
        created() {
            //  this.initPlayer();
        },
        mounted() {
            
        },
        watch:{
            enableFlag:{
                handler:function(){
                    if(this.enableFlag === 1){
                        this.$nextTick(()=>this.initPlayer())
                    }
                    else{
                        this.$nextTick(()=>this.player && this.player.pause())
                    }
                },
                immediate:true,
            }
        },
        // beforeDestroy(){
        //      this.player.destroy();
        // },
        destroyed() {
            // 页面销毁,同时也销毁 TcPlayer
            this.player.dispose();
        },
        methods: {
            initPlayer() {
                let that=this;
                if(this.player){
                     this.player.dispose();  
                }
                this.domId = `video${Math.floor(Math.random()*(99999-10000+1))+parseInt(10000)}`
                let dom = document.createElement('video')
                dom.setAttribute('class', 'video')
                dom.setAttribute('id', this.domId)
                this.$refs['video-outer'].appendChild(dom)
                this.player = TCPlayer(this.domId, {
                    sources: [{ src: this.src, type: 'video/flv' }],
                    autoplay: true, // 是否自动播放
                    controls: true,
                    muted: true,
                    controlBar: {
                        playbackRateMenuButton: false, //是否显示播放速率选择按钮。
                        volumePanel: false,
                        durationDisplay: false,
                        currentTimeDisplay: false,
                        timeDivider: false,
                        volumePanel: false,
                        progressControl: false,
                    },
                });
                    this.player.on('canplay', function(event) {
                    // 从回调参数 event 中获取事件状态码及相关数据
                    //    console.log(event)
                    that.$emit('loadDone',false)
                    // const emit=defineEmits(['loadDone'])
                 
                    // emit('loadDone',false)
                    });
            }
        }
    }
</script>
<style lang="less" scoped>

 .video-player-page{position: relative; width: 100%; height: 100%; overflow: hidden;
        /deep/.video{
                width:100% !important; height: 100% !important;
            }
    }
.player{height: calc((100vh - 350px)/3); position: relative; 
   
    img{width: 100%;height: 100%;}
    span{ position:absolute; top:50%; left: 50%;transform:translate(-50%,-50%); color: white;}
    .noneBox{
        display: flex;
        align-items:center;
        background: #07348a;
        color: #fff;
        line-height: 1em;
        text-align: center;
        position: absolute;
        top: 0;
        z-index: 2;
        width: 100%;
        height: 100%;
    }
    .called{
        z-index: 3;
    }
}

</style>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值