videoTime

This commit is contained in:
shijing 2022-10-31 15:01:28 +08:00
parent 49a375042c
commit 42ef4fb444
2 changed files with 61 additions and 38 deletions

View File

@ -51,6 +51,14 @@ export function getVideoPlayCode(id) {
} }
export function getMyView(id, data) { export function getMyView(id, data) {
return request({
url: `/vod/video/${id}/myview/`,
method: 'get',
data
})
}
export function refreshMyView(id, data) {
return request({ return request({
url: `/vod/video/${id}/myview/`, url: `/vod/video/${id}/myview/`,
method: 'put', method: 'put',

View File

@ -9,7 +9,7 @@
</el-header> </el-header>
<el-main style="margin-top: 70px;"> <el-main style="margin-top: 70px;">
<div style="margin:20px 12%;"> <div style="margin:20px 12%;">
<div class="content" @click="clicknub"> <div class="content">
<video <video
:id="tcPlayerId" :id="tcPlayerId"
width="1000" width="1000"
@ -39,7 +39,7 @@
</el-container> </el-container>
</template> </template>
<script> <script>
import {getVideo, getMyView, getVideoPlayCode} from "@/api/video"; import {getVideo, getMyView,refreshMyView, getVideoPlayCode} from "@/api/video";
export default { export default {
name: 'TencentPlayer', name: 'TencentPlayer',
props: { props: {
@ -61,11 +61,11 @@
description: '', description: '',
name: '', name: '',
videoFileid:false, videoFileid:false,
userName:"" userName:"",
playTimer:null,
}; };
}, },
mounted(){ mounted(){
//debugger;
this.userName = this.$store.state.user.name; this.userName = this.$store.state.user.name;
if(this.player!==null){ if(this.player!==null){
this.player.null; this.player.null;
@ -94,7 +94,6 @@
this.getPlayCode(this.videoFileId); this.getPlayCode(this.videoFileId);
this.getVideo(); this.getVideo();
}, },
methods: { methods: {
getVideo() { getVideo() {
getVideo(this.id).then((response) => { getVideo(this.id).then((response) => {
@ -108,8 +107,6 @@
let that = this; let that = this;
getVideoPlayCode(id).then(res=>{ getVideoPlayCode(id).then(res=>{
if(res.data){ if(res.data){
//debugger;
console.log(res.data);
that.videoFileid = true; that.videoFileid = true;
that.videoPsign = res.data.psign; that.videoPsign = res.data.psign;
that.initVideo(); that.initVideo();
@ -118,48 +115,66 @@
}, },
//视频观看次数 //视频观看次数
clicknub() { clicknub() {
debugger;
getMyView(this.id).then((response) => {}); getMyView(this.id).then((response) => {});
}, },
initVideo() { initVideo() {
//debugger;
console.log(this.userName);
let that = this; let that = this;
let text = "用户:"+that.userName; getMyView(that.id,{}).then((response) => {
const playerParm = { debugger;
fileID: that.videoFileId, console.log(response.data);
appID: that.videoAppId, let current = response.data.current;
psign: that.videoPsign, let playerParm = {
plugins:{ fileID: that.videoFileId,
DynamicWatermark: { appID: that.videoAppId,
speed: 0.1, psign: that.videoPsign,
content: "用户:"+that.userName plugins:{
DynamicWatermark: {
speed: 0.1,
content: "用户:"+that.userName
},
} }
};
if (!that.player) {
that.player = window.TCPlayer(that.tcPlayerId, playerParm);
} else {
that.player.loadVideoByID(playerParm);
that.player.loadVideoByID(that.tcPlayerId);
} }
}; that.player.currentTime(current);
/* //视频播放
* plugins: {
ContinuePlay: { // 开启续播功能
// auto: true, //[可选] 是否在视频播放后自动续播
// text:'上次播放至 ', //[可选] 提示文案
// btnText: '恢复播放' //[可选] 按钮文案
},
}
* */
//debugger;
if (!that.player) {
that.player = window.TCPlayer(that.tcPlayerId, playerParm);
that.player.on('play', function(error) { that.player.on('play', function(error) {
// 做一些处理 if(that.playTimer!==null){
getMyView(that.id).then((response) => {}); clearInterval(that.playTimer);
that.playTimer = null;
}
that.playTimer = setInterval(function(){
let currentTimeNum = 0;
currentTimeNum = that.player.currentTime();
console.log(currentTimeNum);
refreshMyView(that.id,{current:currentTimeNum}).then((response) => {});
},10000)
}); });
} else { //视频暂停
that.player.loadVideoByID(playerParm); that.player.on('pause', function(error) {
that.player.loadVideoByID(that.tcPlayerId); let currentTimeNum = 0;
} currentTimeNum = that.player.currentTime();
console.log(currentTimeNum);
refreshMyView(that.id,{current:currentTimeNum}).then((response) => {});
clearInterval(that.playTimer);
that.playTimer = null;
});
//视频观看中
that.player.on('playing', function(error) {
});
});
}, },
}, },
beforeDestroy () { beforeDestroy () {
if(that.playTimer!==null){
clearInterval(that.playTimer);
that.playTimer = null;
}
this.player.dispose() this.player.dispose()
} }
}; };