当前位置: 首页 > news >正文

vue3使用西瓜播放器播放flv、hls、mp4视频

vue3使用西瓜播放器播放flv、hls、mp4视频

安装相关的插件

npm install xgplayer

npminstall xgplayer-flv

npm install xgplayer-hls

npm install  xgplayer-mp4

组件封装

<template><div :id="`${playerId}`" />
</template>
<script setup lang="ts">
import Player from 'xgplayer'
import FlvPlugin from 'xgplayer-flv'
import HlsPlugin from 'xgplayer-hls'
import Mp4Plugin from 'xgplayer-mp4'
import 'xgplayer/dist/index.min.css'
import { ref, watch, onMounted, onUnmounted } from 'vue'interface propsType {playerId?: stringwidth?: numberheight?: numberurl: stringplugin?: 'flv' | 'hls' | 'mp4'fitVideoSize?: 'fixed' | 'fixWidth' | 'fixHeight' | undefinedcontrols?: boolean
}const props = withDefaults(defineProps<propsType>(), {playerId: 'playerContainer',width: 640,height: 320,url: '',plugin: 'hls',fitVideoSize: 'fixWidth',controls: true
})
const player = ref<any>(null)
const clientWidth = ref<number>(1920)
const clientHeight = ref<number>(1080)onMounted(() => {init()clientWidth.value = document.body.clientWidthclientHeight.value = document.body.clientHeightwindow.addEventListener('resize',() => {clientWidth.value = document.body.clientWidthclientHeight.value = document.body.clientHeightinit()},false)
})
watch(() => props.url,() => {init()},{ deep: true }
)
const getPlugins = () => {let plugins = [Mp4Plugin]switch (props.plugin) {case 'hls':// @ts-expect-error version报错plugins = [HlsPlugin]breakcase 'flv':// @ts-expect-error version报错plugins = [FlvPlugin]breakdefault:plugins = [Mp4Plugin]break}return plugins
}
const init = async () => {player.value = new Player({id: props.playerId,isLive: true,autoplayMuted: true,autoplay: true,plugins: await getPlugins(),url: props.url,fitVideoSize: props.fitVideoSize,height: props.height * (clientHeight.value / 1080),width: props.width * (clientWidth.value / 1920),lang: 'zh-cn',controls: props.controls})
}
/*** 销毁播放器*/
onUnmounted(() => {player.value.destroy()
})
</script>

http://www.lryc.cn/news/235712.html

相关文章:

  • 【Promise12数据集】Promise12数据集介绍和预处理
  • Qt设置整体背景颜色
  • Stream流常见操作
  • INFINI Labs 产品更新 | 发布 Easysearch Java 客户端,Console 支持 SQL 查询等功能
  • 前端调试只会console.log()?
  • CentOS Linux release 7.9.2009 (Core)中安装配置Tomcat
  • 移动机器人路径规划(四)--- 考虑机器人模型下的运动规划KINODYNAMIC PATHFINDING
  • 服务器数据恢复—VMware虚拟化下误操作导致服务器崩溃的数据恢复案例
  • 微服务实战系列之Gateway
  • GZ038 物联网应用开发赛题第10套
  • 重生之我是一名程序员 35
  • 计算机毕业设计选题推荐-点餐微信小程序/安卓APP-项目实战
  • 分享禁止Win10更新的两种方法
  • SPASS-回归分析
  • 【使用vscode在线web搭建开发环境--code-server搭建】
  • c++ list容器使用详解
  • 【案例】可视化大屏
  • js制作动态表单
  • 解决Kibana初始化失败报错: Unable to connect to Elasticsearch
  • 流媒体服务器
  • Java GUI小程序之图片浏览器
  • Kafka-4.1-工作原理综述
  • Linux八股文
  • SPASS-偏相关分析
  • 第二证券:今日投资前瞻:小米汽车引关注 全球风光有望持续高速发展
  • Docker中的RabbitMQ已经启动运行,但是管理界面打不开
  • 自动化网络图软件
  • 如何基于亚马逊云科技打造高性能的 SQL 向量数据库 MyScale
  • 《轻松入门!快速安装PyCharm,打造高效Python编程环境》
  • Golang环境搭建Win10(简洁版)