增加视频播放开始和结束请求
This commit is contained in:
parent
aeb81fd2e5
commit
acf20d8f71
|
|
@ -119,3 +119,12 @@ export function getDrawCount(data){
|
|||
data
|
||||
})
|
||||
}
|
||||
|
||||
//播放开始或者结束
|
||||
export function playStatus(data){
|
||||
return http.request({
|
||||
url: 'course/viewCourse',
|
||||
method:'GET',
|
||||
data
|
||||
})
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@
|
|||
<view class="item" @appear="appear" @disappear="disappear" @click.stop>
|
||||
|
||||
<video class="u-flex-1 video" :show-fullscreen-btn="false" @controlstoggle="controlstoggles" v-if="showVideo"
|
||||
@timeupdate="timeupdate"
|
||||
@waiting="waiting()" object-fit="cover" @pause="onpause" @click="videoClick()"
|
||||
@play="videoPlay('myVideo'+item.courseDetailsId,item.courseDetailsId)" :play-strategy="2"
|
||||
:show-loading="true" codec="software" :muted="false" :show-center-play-btn="true" :loop="false"
|
||||
|
|
@ -53,6 +54,7 @@
|
|||
</template>
|
||||
|
||||
<script setup>
|
||||
import * as Api from '@/api/video/index.js'
|
||||
import {
|
||||
computed,
|
||||
nextTick,
|
||||
|
|
@ -157,7 +159,42 @@
|
|||
emits('showInfo', newval)
|
||||
})
|
||||
|
||||
|
||||
//是否是第一次加载时的播放,不是暂停再播放
|
||||
let isFirstPlay=true
|
||||
let isPlayFinish=false//是否播放完成
|
||||
/**
|
||||
* @param {type} = [start,end]
|
||||
*/
|
||||
function sendPlayStatus(type='start'){
|
||||
Api.playStatus({
|
||||
courseId:props.item.courseId,
|
||||
courseDetailsId:props.item.courseDetailsId,
|
||||
type
|
||||
})
|
||||
}
|
||||
|
||||
function timeupdate(e){
|
||||
//隐藏loding
|
||||
// #ifdef H5
|
||||
uni.hideLoading()
|
||||
// #endif
|
||||
if(isPlayFinish){
|
||||
return
|
||||
}
|
||||
if (e.detail.currentTime > e.detail.duration * 0.9) {
|
||||
if (!isFirstPlay) {
|
||||
sendPlayStatus('end')
|
||||
isPlayFinish=true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function videoPlay() {
|
||||
if(isFirstPlay&&!isPlayFinish){
|
||||
sendPlayStatus('start')
|
||||
}
|
||||
isFirstPlay=false
|
||||
isPlying.value = true
|
||||
// #ifdef H5
|
||||
emits('controlstoggles', {
|
||||
|
|
@ -183,7 +220,7 @@
|
|||
|
||||
|
||||
function ended() {
|
||||
|
||||
Api.playStatus('end')
|
||||
}
|
||||
|
||||
function dianzanClick() {
|
||||
|
|
@ -270,6 +307,8 @@
|
|||
watch(() => showVideo.value, (newval) => {
|
||||
console.log('showVideo change:'+newval);
|
||||
if (newval) {
|
||||
isFirstPlay=true
|
||||
isPlayFinish=false
|
||||
nextTick(()=>{
|
||||
init()
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in New Issue