|
@@ -1,12 +1,12 @@
|
|
|
<template>
|
|
|
<div>
|
|
|
+ <!-- @timeupdate="onPlayerTimeupdate($event)" -->
|
|
|
<video-player
|
|
|
class="video-player vjs-custom-skin"
|
|
|
ref="videoPlayer"
|
|
|
:playsinline="true"
|
|
|
@pause="onPlayerPause($event)"
|
|
|
@play="onPlayerStart($event)"
|
|
|
- @timeupdate="onPlayerTimeupdate($event)"
|
|
|
@ready="playerReadied"
|
|
|
@ended="onPlayerEnded($event)"
|
|
|
:globalOptions="{controls:true}"
|
|
@@ -109,10 +109,8 @@
|
|
|
}
|
|
|
},
|
|
|
beforeDestroy() {
|
|
|
- if (this.timer) {
|
|
|
- console.log("beforeDestroy")
|
|
|
- clearInterval(this.timer); //关闭
|
|
|
- }
|
|
|
+ this.stopTick()
|
|
|
+ this.reportErr("play", 'destroy');
|
|
|
},
|
|
|
computed: {
|
|
|
player() {
|
|
@@ -121,21 +119,27 @@
|
|
|
},
|
|
|
created() {
|
|
|
this.startTick()
|
|
|
+ // this.startMonitor()
|
|
|
},
|
|
|
methods: {
|
|
|
startTick(){
|
|
|
- console.log("startTick")
|
|
|
- let tick = this.tick;
|
|
|
+ let tick = this.tryTick;
|
|
|
if( this.timer ) clearInterval(this.timer);
|
|
|
this.timer = setInterval(tick, 5 * 1000);
|
|
|
},
|
|
|
stopTick(){
|
|
|
- console.log("stopTick")
|
|
|
if( this.timer ) clearInterval(this.timer);
|
|
|
},
|
|
|
+ tryTick(){
|
|
|
+ let that = this;
|
|
|
+ try {
|
|
|
+ that.tick()
|
|
|
+ }catch(err){
|
|
|
+ that.reportErr("play", ''+err.message )
|
|
|
+ }
|
|
|
+ },
|
|
|
playerReadied(player) {
|
|
|
let that = this;
|
|
|
- console.log("init", this.media.position);
|
|
|
if( this.media.position){
|
|
|
this.setposition( this.media.position );
|
|
|
}else{
|
|
@@ -158,19 +162,22 @@
|
|
|
let player = this.$refs.videoPlayer.player;
|
|
|
player.currentTime( position );
|
|
|
if( this.media.isFinish) return;
|
|
|
- if( this.media.position >= this.media.duration-30 && !this.media.isFinish){
|
|
|
+ if( this.media.position >= this.media.duration-10 && !this.media.isFinish){
|
|
|
this.tick( true )
|
|
|
}
|
|
|
this.onPlay = true
|
|
|
},
|
|
|
onPlayerPause(event) {
|
|
|
+ this.reportErr("play", 'pause' );
|
|
|
this.stopTick()
|
|
|
this.onPlay = false
|
|
|
},
|
|
|
onPlayerEnded( event ){
|
|
|
+ this.reportErr("play", 'end' );
|
|
|
this.tick( true )
|
|
|
},
|
|
|
onClose(){
|
|
|
+ this.reportErr("play", 'close')
|
|
|
this.doPause()
|
|
|
this.$emit("close")
|
|
|
},
|
|
@@ -178,7 +185,6 @@
|
|
|
this.stopTick()
|
|
|
let myPlayer = this.$refs.videoPlayer.player;
|
|
|
myPlayer && myPlayer.pause()
|
|
|
- console.log("doPause")
|
|
|
this.onPlay = false
|
|
|
},
|
|
|
doPlay(){
|
|
@@ -191,18 +197,30 @@
|
|
|
this.tickNum = 0
|
|
|
},
|
|
|
onPlayerStart() {
|
|
|
+ this.reportErr("play", 'start');
|
|
|
this.startTick();
|
|
|
this.onPlay = true
|
|
|
},
|
|
|
startMonitor() {
|
|
|
let that = this
|
|
|
- window.onblur = function() {
|
|
|
- that.doPause()
|
|
|
- }
|
|
|
- window.onfocus = function () {
|
|
|
- that.doPlay()
|
|
|
- }
|
|
|
+ document.addEventListener("visibilitychange", function() {
|
|
|
+ // || document.hidden
|
|
|
+ if( document.visibilityState == "hidden"){
|
|
|
+ that.doPause( )
|
|
|
+ }else{
|
|
|
+ that.doPlay()
|
|
|
+ }
|
|
|
+ });
|
|
|
},
|
|
|
+ // startMonitor() {
|
|
|
+ // let that = this
|
|
|
+ // window.onblur = function() {
|
|
|
+ // that.doPause()
|
|
|
+ // }
|
|
|
+ // window.onfocus = function () {
|
|
|
+ // that.doPlay()
|
|
|
+ // }
|
|
|
+ // },
|
|
|
tickWait(){
|
|
|
this.doPause()
|
|
|
let that = this
|
|
@@ -222,6 +240,9 @@
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
+ reportErr( action, msg ){
|
|
|
+ httpServer("course.report", {action, msg})
|
|
|
+ },
|
|
|
tick( force = false) {
|
|
|
let media = this.media;
|
|
|
this.tickNum ++
|
|
@@ -242,13 +263,12 @@
|
|
|
|
|
|
let isFinish = force?1:0
|
|
|
if( curTimes >= media.duration ) isFinish = 1;
|
|
|
- console.log("tick", curTimes, isFinish)
|
|
|
// 拉到后面
|
|
|
if( !isFinish ){
|
|
|
if ( !this.onPlay ) return;
|
|
|
}
|
|
|
// 强制完成
|
|
|
- let param ={id: media.id, position:curTimes ,isFinish};
|
|
|
+ let param ={id: media.id, position:curTimes, isFinish};
|
|
|
httpServer("course.tick", param, true).then( res => {
|
|
|
if (res.code == 200) {
|
|
|
let {skip, position, pause, closed} = res.data
|
|
@@ -266,8 +286,6 @@
|
|
|
Object.assign(param, res.data )
|
|
|
this.$emit("update", param )
|
|
|
}
|
|
|
- }).catch( res =>{
|
|
|
- console.log( "tick", res)
|
|
|
})
|
|
|
}
|
|
|
}
|