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

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使用FastAPI实现大文件分片上传与断点续传功能

《Python使用FastAPI实现大文件分片上传与断点续传功能》大文件直传常遇到超时、网络抖动失败、失败后只能重传的问题,分片上传+断点续传可以把大文件拆成若干小块逐个上传,并在中断后从已完成分片继... 目录一、接口设计二、服务端实现(FastAPI)2.1 运行环境2.2 目录结构建议2.3 serv

Python一次性将指定版本所有包上传PyPI镜像解决方案

《Python一次性将指定版本所有包上传PyPI镜像解决方案》本文主要介绍了一个安全、完整、可离线部署的解决方案,用于一次性准备指定Python版本的所有包,然后导出到内网环境,感兴趣的小伙伴可以跟随... 目录为什么需要这个方案完整解决方案1. 项目目录结构2. 创建智能下载脚本3. 创建包清单生成脚本4

Spring Security简介、使用与最佳实践

《SpringSecurity简介、使用与最佳实践》SpringSecurity是一个能够为基于Spring的企业应用系统提供声明式的安全访问控制解决方案的安全框架,本文给大家介绍SpringSec... 目录一、如何理解 Spring Security?—— 核心思想二、如何在 Java 项目中使用?——

SpringBoot+RustFS 实现文件切片极速上传的实例代码

《SpringBoot+RustFS实现文件切片极速上传的实例代码》本文介绍利用SpringBoot和RustFS构建高性能文件切片上传系统,实现大文件秒传、断点续传和分片上传等功能,具有一定的参考... 目录一、为什么选择 RustFS + SpringBoot?二、环境准备与部署2.1 安装 RustF

springboot中使用okhttp3的小结

《springboot中使用okhttp3的小结》OkHttp3是一个JavaHTTP客户端,可以处理各种请求类型,比如GET、POST、PUT等,并且支持高效的HTTP连接池、请求和响应缓存、以及异... 在 Spring Boot 项目中使用 OkHttp3 进行 HTTP 请求是一个高效且流行的方式。

Java使用Javassist动态生成HelloWorld类

《Java使用Javassist动态生成HelloWorld类》Javassist是一个非常强大的字节码操作和定义库,它允许开发者在运行时创建新的类或者修改现有的类,本文将简单介绍如何使用Javass... 目录1. Javassist简介2. 环境准备3. 动态生成HelloWorld类3.1 创建CtC

使用Python批量将.ncm格式的音频文件转换为.mp3格式的实战详解

《使用Python批量将.ncm格式的音频文件转换为.mp3格式的实战详解》本文详细介绍了如何使用Python通过ncmdump工具批量将.ncm音频转换为.mp3的步骤,包括安装、配置ffmpeg环... 目录1. 前言2. 安装 ncmdump3. 实现 .ncm 转 .mp34. 执行过程5. 执行结

Java使用jar命令配置服务器端口的完整指南

《Java使用jar命令配置服务器端口的完整指南》本文将详细介绍如何使用java-jar命令启动应用,并重点讲解如何配置服务器端口,同时提供一个实用的Web工具来简化这一过程,希望对大家有所帮助... 目录1. Java Jar文件简介1.1 什么是Jar文件1.2 创建可执行Jar文件2. 使用java

C#使用Spire.Doc for .NET实现HTML转Word的高效方案

《C#使用Spire.Docfor.NET实现HTML转Word的高效方案》在Web开发中,HTML内容的生成与处理是高频需求,然而,当用户需要将HTML页面或动态生成的HTML字符串转换为Wor... 目录引言一、html转Word的典型场景与挑战二、用 Spire.Doc 实现 HTML 转 Word1

SpringBoot实现不同接口指定上传文件大小的具体步骤

《SpringBoot实现不同接口指定上传文件大小的具体步骤》:本文主要介绍在SpringBoot中通过自定义注解、AOP拦截和配置文件实现不同接口上传文件大小限制的方法,强调需设置全局阈值远大于... 目录一  springboot实现不同接口指定文件大小1.1 思路说明1.2 工程启动说明二 具体实施2