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

news/2025/1/12 21:40:27/

上传方法如下

在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.ppmy.cn/news/364642.html

相关文章

阿里云视频点播相关代码

官网:阿里云登录 - 欢迎登录阿里云&#xff0c;安全稳定的云计算服务平台 依赖 版本: <aliyun-java-sdk-core.version>4.3.3</aliyun-java-sdk-core.version> <aliyun-sdk-oss.version>3.1.0</aliyun-sdk-oss.version> <aliyun-java-sdk-vod.vers…

腾讯云点播步骤

我们演示一个简单的播放直播 具体可以去腾讯云平台看 去平台下载一个Demo 首先导包 跟jni目录 布局 <?xml version"1.0" encoding"utf-8"?> <RelativeLayoutxmlns:android"http://schemas.android.com/apk/res/android"xmlns:t…

05-阿里云视频点播服务与谷粒学院整合视频点播技术

阿里云视频点播服务与谷粒学院整合视频点播技术 一.应用场景 音视频网站&#xff1a;无论是初创视频服务企业&#xff0c;还是已拥有海量视频资源&#xff0c;可定制化的点播服务帮助客户快速搭建拥有极致观看体验、安全可靠的视频点播应用。短视频&#xff1a;集音视频拍摄、…

阿里云视频点播详解

整理了一下阿里云的视频点播相关的问题&#xff0c;记下来&#xff0c;以备后用。 阿里云视频点播是近几年刚有的服务&#xff0c;与OSS结合较深。开发之初找到有用的文档实在少之又少&#xff0c;所以把完整的开发流程已经我遇到一些问题记录下来。阿里云视频点播介绍: 能查到…

达梦运维管理v1.0

达梦运维管理1.0 日志类 重做日志 select * from v$rlogfile; select * from v$rlog;添加联机日志&#xff1a;&#xff08;以M为单位&#xff09; alter database add logfile /dmdata/DAMENG/REDO/DAMENG03.log size 256;修改联机日志大小&#xff1a; alter database r…

【谷粒学院】阿里云视频点播VOD功能笔记

文章目录 1、准备工作2、代码详解3、测试结果 1、准备工作 首先配置文件中需要配置好阿里云相关id和密钥&#xff08;和阿里云OSS配置一样&#xff09; 如果不知道id和密钥&#xff0c;就去阿里云官网进行服务开通申请就可以得到 2、代码详解 配置类&#xff1a;用于读取配…

腾讯云点播视频播放器使用步骤 uniapp

微信开发后台 首先需要微信小程序的账号&#xff0c;各种认证&#xff0c;信息填写完整&#xff0c; 然后–>设置–>第三方设置–>插件管理–>添加插件–>搜索云点播短视频播放器–>添加插件 项目开发 在page.json文件中的globalStyle下面加入 "usin…

同星T1014在线回放设置

同星T1014在线回放设置以及常见问题解决方法 1.同星T1014连接硬件进行在线数据回放 1.将同星T1014硬件连接到到电脑中&#xff1b; 2.打开TSMaster软件&#xff0c;在通道选择选项中配置通道&#xff0c;该硬件最大支持四路通道&#xff0c;所以我这里选择四路通道&#xff1b…