vue使用西瓜视频插件xgplayer

2024-03-07 13:20

本文主要是介绍vue使用西瓜视频插件xgplayer,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

Vue2

npm install xgplayer-vue@latest

引入xgplayer,封装成一个公共组件

src/components/xgPlayer/xgPlayer.vue

<template><Xgplayer :config="config" @player="Player = $event" />
</template><script>
import Xgplayer from 'xgplayer-vue'
export default {components: {Xgplayer},data () {return {config: {id: 'vs',url: 'https://sf1-cdn-tos.huoshanstatic.com/obj/media-fe/xgplayer_doc_video/mp4/xgplayer-demo-360p.mp4', // 修改为能播放的视频地址width: '50%', // 宽度可以是 数字 ,也可以是百分比height: 500,// autoplay: true,download: true,poster: 'http://lf9-cdn-tos.bytecdntp.com/cdn/expire-1-M/byted-player-videos/1.0.0/poster.jpg',playbackRate: [0.5, 0.75, 1, 1.5, 2] // 倍速},Player: null}}
}</script><style>
#xgPlayer{border: 1px solid red;
}
</style>

 组件中使用 

<template><div><h1>播放器</h1><Player  /></div>
</template><script>
import Player from '@/components/xgPlayer/xgPlayer.vue'
export default {name: 'chartContainer',components: {Player},
</script><style></style>

Vue3

<template><div style="width: 100%; height: 100%":id="id"></div>
</template>
<script setup>
import { onMounted, watch } from 'vue'
import Player from 'xgplayer'const props = defineProps({id: {type: String,required: true,},videoUrl: {type: String,default: () =>'https://sf1-cdn-tos.huoshanstatic.com/obj/media-fe/xgplayer_doc_video/mp4/xgplayer-demo-360p.mp4',},poster: {type: String,default: () =>'http://lf9-cdn-tos.bytecdntp.com/cdn/expire-1-M/byted-player-videos/1.0.0/poster.jpg',},playsinline: {type: Boolean,default: true,},width: {type: String,default: '50%',},height: {type: String,default: '50%',},
})watch(() => props.videoUrl,(newUrl) => {initPlayer()},{deep: true,}
)onMounted(() => {initPlayer()
})// 初始化西瓜视频
const initPlayer = () => {let player = new Player({id: props.id,url: props.videoUrl,poster: props.poster,playsinline: props.playsinline,height: props.height,width: props.width,thumbnail: {pic_num: 44,width: 160,height: 90,col: 10,row: 10,urls: ['//lf9-cdn-tos.bytecdntp.com/cdn/expire-1-M/byted-player-videos/1.0.0/xgplayer-demo-thumbnail.jpg',],},danmu: {comments: [{duration: 15000,id: '1',start: 3000,txt: '长弹幕长弹幕长弹幕长弹幕长弹幕',style: {//弹幕自定义样式color: '#ff9500',fontSize: '20px',border: 'solid 1px #ff9500',borderRadius: '50px',padding: '5px 11px',backgroundColor: 'rgba(255, 255, 255, 0.1)',},},],area: {start: 0,end: 1,},},whitelist: [''],})//  超清、高清、标清 分别对应的地址player.emit('resourceReady', [{name: '超清',url: '//sf1-cdn-tos.huoshanstatic.com/obj/media-fe/xgplayer_doc_video/mp4/xgplayer-demo-720p.mp4',},{name: '高清',url: '//sf1-cdn-tos.huoshanstatic.com/obj/media-fe/xgplayer_doc_video/mp4/xgplayer-demo-720p.mp4',},{name: '标清',url: '//sf1-cdn-tos.huoshanstatic.com/obj/media-fe/xgplayer_doc_video/mp4/xgplayer-demo-720p.mp4',}])
}
</script>
<template><div class="bigBox"><h1>播放器</h1><XgPlayer :id="'xgPlayer'" /></div></template><script lang="ts" setup>
import XgPlayer from '@/components/xgPlayer/xgPlayer.vue'
import 'xgplayer/dist/index.min.css'
</script><style scoped>
.bigBox{height: 95vh !important;
}
</style>

这篇关于vue使用西瓜视频插件xgplayer的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/783660

相关文章

Java中的ConcurrentBitSet使用小结

《Java中的ConcurrentBitSet使用小结》本文主要介绍了Java中的ConcurrentBitSet使用小结,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,... 目录一、核心澄清:Java标准库无内置ConcurrentBitSet二、推荐方案:Eclipse

Go语言结构体标签(Tag)的使用小结

《Go语言结构体标签(Tag)的使用小结》结构体标签Tag是Go语言中附加在结构体字段后的元数据字符串,用于提供额外的属性信息,这些信息可以通过反射在运行时读取和解析,下面就来详细的介绍一下Tag的使... 目录什么是结构体标签?基本语法常见的标签用途1.jsON 序列化/反序列化(最常用)2.数据库操作(

Java中ScopeValue的使用小结

《Java中ScopeValue的使用小结》Java21引入的ScopedValue是一种作用域内共享不可变数据的预览API,本文就来详细介绍一下Java中ScopeValue的使用小结,感兴趣的可以... 目录一、Java ScopedValue(作用域值)详解1. 定义与背景2. 核心特性3. 使用方法

spring中Interceptor的使用小结

《spring中Interceptor的使用小结》SpringInterceptor是SpringMVC提供的一种机制,用于在请求处理的不同阶段插入自定义逻辑,通过实现HandlerIntercept... 目录一、Interceptor 的核心概念二、Interceptor 的创建与配置三、拦截器的执行顺

C#中checked关键字的使用小结

《C#中checked关键字的使用小结》本文主要介绍了C#中checked关键字的使用,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学... 目录✅ 为什么需要checked? 问题:整数溢出是“静默China编程”的(默认)checked的三种用

C#中预处理器指令的使用小结

《C#中预处理器指令的使用小结》本文主要介绍了C#中预处理器指令的使用,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧... 目录 第 1 名:#if/#else/#elif/#endif✅用途:条件编译(绝对最常用!) 典型场景: 示例

VSCode开发中有哪些好用的插件和快捷键

《VSCode开发中有哪些好用的插件和快捷键》作为全球最受欢迎的编程工具,VSCode的快捷键体系是提升开发效率的核心密码,:本文主要介绍VSCode开发中有哪些好用的插件和快捷键的相关资料,文中... 目录前言1、vscode插件1.1 Live-server1.2 Auto Rename Tag1.3

Mysql中RelayLog中继日志的使用

《Mysql中RelayLog中继日志的使用》MySQLRelayLog中继日志是主从复制架构中的核心组件,负责将从主库获取的Binlog事件暂存并应用到从库,本文就来详细的介绍一下RelayLog中... 目录一、什么是 Relay Log(中继日志)二、Relay Log 的工作流程三、Relay Lo

使用Redis实现会话管理的示例代码

《使用Redis实现会话管理的示例代码》文章介绍了如何使用Redis实现会话管理,包括会话的创建、读取、更新和删除操作,通过设置会话超时时间并重置,可以确保会话在用户持续活动期间不会过期,此外,展示了... 目录1. 会话管理的基本概念2. 使用Redis实现会话管理2.1 引入依赖2.2 会话管理基本操作

Springboot请求和响应相关注解及使用场景分析

《Springboot请求和响应相关注解及使用场景分析》本文介绍了SpringBoot中用于处理HTTP请求和构建HTTP响应的常用注解,包括@RequestMapping、@RequestParam... 目录1. 请求处理注解@RequestMapping@GetMapping, @PostMappin