腾讯点播云,上传视频实例, 使用点播云播放器实例

2024-02-09 01:32

本文主要是介绍腾讯点播云,上传视频实例, 使用点播云播放器实例,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

上传方法如下

在elementui自定义上传方法中必须写成promise的形式,其他的可以参考官网使用

   async up ({ commit, state }, params) {let originDomain = nullreturn new Promise((resolve, reject) => {const tcVod = new TcVod({getSignature: getSignature // 前文中所述的获取上传签名的函数})const uploader = tcVod.upload({mediaFile: params.files[0] // 媒体文件(视频或音频或图片),类型为 File})uploader.on('media_progress', info => {// info.name = params.files[0].name// info.uid  = params.files[0].uidparams.onprogress(info)})uploader.done().then(doneResult => {doneResult.video.url = doneResult.video.url.replace(originDomain, state.vodFileUrl)resolve(doneResult)}).catch(err => {reject(err)})})function getSignature () {return axios.post(state.upUrl).then(function (response) {originDomain = response.data.data.originDomainreturn response.data.data.sign})}},

elementui自定义上传使用

 <el-uploadref="upload"action=""list-type="picture-card":on-preview="handleView":on-progress="handleProgerss":on-remove="handleRemove"name="file":headers = "uploadHeaders"multipleshow-file-list:accept="'jpg,jpeg,png'"auto-upload:on-success="handleSuccess":on-exceed="handleExceed":before-upload="handleBeforeUpload":on-error="handleError":limit="limit":file-list="newFileList":http-request="uploadCos2"class="imageList"><i class="el-icon-plus"></i></el-upload>

在方法中使用上传函数,注意回调函数onprogress的使用

 async uploadCos2 (fileObj) {try{const result = await this.up({files: [fileObj.file], dirType: this.dirType, onprogress: (file)=>{const percent = file.percent?parseInt(file.percent*100):0fileObj.onProgress({ percent: percent })}})console.info(this.$refs.upload.uploadFiles)this.$refs.upload.uploadFiles.forEach(f=>{if(f.uid === fileObj.file.uid){f.url = result.video.url}})}catch(err){this.$message.error(`上传文件失败:${err}`)}},

使用点播云超级播放器

如果只有一个视频,参考官网使用,如果有多个视频,需要切换路径,参考代码如下,采用动态创建标签的形式进行使用

在template里面创建一个标签

        <div style="display: inline-block" class="my-play" id="MyPlay"></div>

在方法中使用

 playVideo () {const self = thisconst playbox = document.getElementById('MyPlay')const video = document.createElement('video')video.className = 'playsinline webkit-playsinline'video.setAttribute('id', 'tcPlayerId' + self.activeId)playbox.appendChild(video)setTimeout(() => {self.$nextTick(() => {self.loading = false// eslint-disable-next-line no-undefself.player = TCPlayer('tcPlayerId' + this.activeId, self.optionsPlayer)console.log(self.player)self.player.play()})}, 200)}
// 切换视频changeVideo (item) {if (this.activeId === item._id) {return}this.loading = truethis.activeId = item._idthis.optionsPlayer.fileID = item.uidthis.optionsPlayer.poster = item.posterif (this.player) {this.player.dispose()}this.videoPlay = {url: item.url,name: item.name,poster: item.poster}this.playVideo()},
<template><div class=" bg-gray29" v-if="videoPlay.url"><div class="flex"><div class="flex-1"><div style="display: inline-block" class="my-play" id="MyPlay"><!--          <template><video :id="'tcPlayerId' + activeId" preload="auto" ></video></template>--></div><CommonVideo v-if="false" class="border-4 border-transparent border-b-0" :videourl="videoPlay.url" :poster="videoPlay.poster?videoPlay.poster:poster"></CommonVideo></div><div class="w-96 border-t-4 border-gray29 px-2 bg-black pt-10" style="padding-top: 26px;padding-bottom: 16px;"><div class="text-1.67rem text-white font-bold">视频列表</div><div class="overflow-y-auto ms-scroll" style="height: 33rem"><div class="flex cursor-pointer" @click="changeVideo(item)" :class="[activeId===item._id?'bg-gray29 text-color-primary':'']" v-for="item in videos" :key="item._id" style="height: 90px;padding: 10px 7px" ><img :src="item.poster?item.poster +'!13120.PNG':poster +'!13120.PNG'" style="width: 124px;height: 70px;border-width: 2px;" class="object-cover border-transparent flex-none" :class="activeId===item._id?'border-color-primary':''"/><div class="flex-auto text-white pl-1 flex items-center flex-col justify-between"><div :title="item.name" style="font-size: 14px;line-height: 16px;word-wrap: break-word;word-break: break-all;" class="line-two" :class="item.active?'text-color-primary':''">{{item.name}}</div><div>{{item.duration?$moment.utc(item.duration * 1000).format('HH:mm:ss'):''}}</div></div></div></div></div></div></div>
</template><script>
import CommonVideo from '@/components/CommonVideo'
import { mapState } from 'vuex'
export default {name: 'Video',props: ['videos', 'poster', 'videoinfo'],components: {CommonVideo},data () {return {loading: false,videoPlay: {url: '',name: '',poster: ''},activeId: null,optionsPlayer: {fileID: '', // 请传入需要播放的视频 filID(必须)appID: '', // 请传入点播账号的 appID(必须)poster: '',width: 852,height: 472,preload: 'auto',plugins: {ContinuePlay: { // 开启续播功能auto: true, // [可选] 是否在视频播放后自动续播text: '上次播放至 ', // [可选] 提示文案btnText: '恢复播放' // [可选] 按钮文案}}},player: null}},methods: {changeVideo (item) {if (this.activeId === item._id) {return}this.loading = truethis.activeId = item._idthis.optionsPlayer.fileID = item.uidthis.optionsPlayer.poster = item.posterif (this.player) {this.player.dispose()}this.videoPlay = {url: item.url,name: item.name,poster: item.poster}this.playVideo()},playVideo () {const self = thisconst playbox = document.getElementById('MyPlay')const video = document.createElement('video')video.className = 'playsinline webkit-playsinline'video.setAttribute('id', 'tcPlayerId' + self.activeId)playbox.appendChild(video)setTimeout(() => {self.$nextTick(() => {self.loading = false// eslint-disable-next-line no-undefself.player = TCPlayer('tcPlayerId' + this.activeId, self.optionsPlayer)console.log(self.player)self.player.play()})}, 200)}},computed: {...mapState(['cdnUrl','appid'])},created () {this.videoPlay = {url: this.videos[0].url,name: this.videos[0].name,poster: this.videos[0].poster}this.activeId = this.videos[0]._idthis.optionsPlayer.fileID = this.videos[0].uidthis.optionsPlayer.appID = this.$store.state.appidthis.optionsPlayer.poster = this.videos[0].poster},mounted () {this.playVideo()},beforeDestroy () {if (this.player) {this.player.dispose()}}
}
</script>
<style>
.my-play .tcp-skin .vjs-big-play-button {height: 4.8em !important;width: 6.8em !important;left: 50% !important;top: 50% !important;margin-left: -3.4em !important;margin-top: -2.4em !important;font-size: 1em !important;border: 0 !important;opacity: 1 !important;z-index: 1 !important;
}
</style>
<style scoped>
#tcPlayerId{
}
.ms-scroll::-webkit-scrollbar {width: 8px;
}
.ms-scroll::-webkit-scrollbar-track {background-color:transparent;-webkit-border-radius: 2em;-moz-border-radius: 2em;border-radius:2em;
}
.ms-scroll::-webkit-scrollbar-thumb {background: #5A5A5A;-webkit-border-radius: 2em;-moz-border-radius: 2em;border-radius:2em;
}
</style>

 

这篇关于腾讯点播云,上传视频实例, 使用点播云播放器实例的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



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

相关文章

使用Python和Pyecharts创建交互式地图

《使用Python和Pyecharts创建交互式地图》在数据可视化领域,创建交互式地图是一种强大的方式,可以使受众能够以引人入胜且信息丰富的方式探索地理数据,下面我们看看如何使用Python和Pyec... 目录简介Pyecharts 简介创建上海地图代码说明运行结果总结简介在数据可视化领域,创建交互式地

Java Stream流使用案例深入详解

《JavaStream流使用案例深入详解》:本文主要介绍JavaStream流使用案例详解,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录前言1. Lambda1.1 语法1.2 没参数只有一条语句或者多条语句1.3 一个参数只有一条语句或者多

Java Spring 中 @PostConstruct 注解使用原理及常见场景

《JavaSpring中@PostConstruct注解使用原理及常见场景》在JavaSpring中,@PostConstruct注解是一个非常实用的功能,它允许开发者在Spring容器完全初... 目录一、@PostConstruct 注解概述二、@PostConstruct 注解的基本使用2.1 基本代

C#使用StackExchange.Redis实现分布式锁的两种方式介绍

《C#使用StackExchange.Redis实现分布式锁的两种方式介绍》分布式锁在集群的架构中发挥着重要的作用,:本文主要介绍C#使用StackExchange.Redis实现分布式锁的... 目录自定义分布式锁获取锁释放锁自动续期StackExchange.Redis分布式锁获取锁释放锁自动续期分布式

springboot使用Scheduling实现动态增删启停定时任务教程

《springboot使用Scheduling实现动态增删启停定时任务教程》:本文主要介绍springboot使用Scheduling实现动态增删启停定时任务教程,具有很好的参考价值,希望对大家有... 目录1、配置定时任务需要的线程池2、创建ScheduledFuture的包装类3、注册定时任务,增加、删

使用Python实现矢量路径的压缩、解压与可视化

《使用Python实现矢量路径的压缩、解压与可视化》在图形设计和Web开发中,矢量路径数据的高效存储与传输至关重要,本文将通过一个Python示例,展示如何将复杂的矢量路径命令序列压缩为JSON格式,... 目录引言核心功能概述1. 路径命令解析2. 路径数据压缩3. 路径数据解压4. 可视化代码实现详解1

Pandas透视表(Pivot Table)的具体使用

《Pandas透视表(PivotTable)的具体使用》透视表用于在数据分析和处理过程中进行数据重塑和汇总,本文就来介绍一下Pandas透视表(PivotTable)的具体使用,感兴趣的可以了解一下... 目录前言什么是透视表?使用步骤1. 引入必要的库2. 读取数据3. 创建透视表4. 查看透视表总结前言

Python 交互式可视化的利器Bokeh的使用

《Python交互式可视化的利器Bokeh的使用》Bokeh是一个专注于Web端交互式数据可视化的Python库,本文主要介绍了Python交互式可视化的利器Bokeh的使用,具有一定的参考价值,感... 目录1. Bokeh 简介1.1 为什么选择 Bokeh1.2 安装与环境配置2. Bokeh 基础2

Android使用ImageView.ScaleType实现图片的缩放与裁剪功能

《Android使用ImageView.ScaleType实现图片的缩放与裁剪功能》ImageView是最常用的控件之一,它用于展示各种类型的图片,为了能够根据需求调整图片的显示效果,Android提... 目录什么是 ImageView.ScaleType?FIT_XYFIT_STARTFIT_CENTE

Java学习手册之Filter和Listener使用方法

《Java学习手册之Filter和Listener使用方法》:本文主要介绍Java学习手册之Filter和Listener使用方法的相关资料,Filter是一种拦截器,可以在请求到达Servl... 目录一、Filter(过滤器)1. Filter 的工作原理2. Filter 的配置与使用二、Listen