【vue3播放监控视频的组件video】

@[组件解决视频不能播放问题],一个组件直接搞定!!!!

子组件

`<template>
  <div class="videoBox">
    <video ref="videoPlayer" class="video-js vjs-default-skin vjs-big-play-centered"></video>
  </div>
</template>

<script setup lang="ts">
import videojs from "video.js";
import "video.js/dist/video-js.css";
import "videojs-flvjs-es6";
import "videojs-flash";
import { ref, onMounted,onBeforeUnmount } from 'vue';
import zhCN from 'video.js/dist/lang/zh-CN.json'; 
const props = defineProps({
  videoUrl: {
    type: String,
    default: ""
  }
});
const videoPlayer = ref(null);
const handelVideoUrl = () => {
  let options = {
    muted: true,
    controls: true,
    autoplay: true,
    loop: true,
    languages: {  
'zh-CN': zhCN  
},  
    language: "zh-CN",
    preload: "auto",
    notSupportedMessage: '此视频暂无法播放,请稍后再试',
    textTrackDisplay: false
  };

  const url = props.videoUrl.replace(/\s+/g, "");

  if (url.includes("rtmp")) {
    options = {
      ...options,
      techOrder: ["html5", "flash"],
      sources: [{ src: props.videoUrl, type: "rtmp/flv" }]
    };
  } else if (url.endsWith(".flv")) {
    options = {
      ...options,
      techOrder: ["html5", "flvjs"],
      flvjs: {
        mediaDataSource: {
          isLive: false,
          cors: true,
          withCredentials: false
        }
      },
      sources: [{ src: props.videoUrl, type: "video/x-flv" }]
    };
  } else if (url.endsWith(".m3u8")) {
    options = {
      ...options,
      sources: [{ src: props.videoUrl, type: "application/x-mpegURL" }]
    };
  } else {
    options = {
      ...options,
      sources: [{ src: props.videoUrl, type: "video/mp4" }]
    };
  }
  videoPlayer.value = videojs(videoPlayer.value, { ...options });
};

onMounted(() => {
  handelVideoUrl();
});
onBeforeUnmount(() => {
  if (videoPlayer.value) {
    videoPlayer.value.dispose();
  }
});
</script>
<style lang="less" scoped>
.videoBox {
  height: 100%;
  width: 100%;
}
</style>`

在父组件中直接引入即可

1.引入

 import Video from '../../../components/video/index.vue';

2.使用

 <Video :videoUrl="item.CameraUrl" class="video-item"></Video>
  • 22
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值