增加视频播放开始和结束请求
This commit is contained in:
parent
aeb81fd2e5
commit
acf20d8f71
|
|
@ -118,4 +118,13 @@ export function getDrawCount(data){
|
||||||
method:'GET',
|
method:'GET',
|
||||||
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>
|
<view class="item" @appear="appear" @disappear="disappear" @click.stop>
|
||||||
|
|
||||||
<video class="u-flex-1 video" :show-fullscreen-btn="false" @controlstoggle="controlstoggles" v-if="showVideo"
|
<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()"
|
@waiting="waiting()" object-fit="cover" @pause="onpause" @click="videoClick()"
|
||||||
@play="videoPlay('myVideo'+item.courseDetailsId,item.courseDetailsId)" :play-strategy="2"
|
@play="videoPlay('myVideo'+item.courseDetailsId,item.courseDetailsId)" :play-strategy="2"
|
||||||
:show-loading="true" codec="software" :muted="false" :show-center-play-btn="true" :loop="false"
|
:show-loading="true" codec="software" :muted="false" :show-center-play-btn="true" :loop="false"
|
||||||
|
|
@ -53,6 +54,7 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
|
import * as Api from '@/api/video/index.js'
|
||||||
import {
|
import {
|
||||||
computed,
|
computed,
|
||||||
nextTick,
|
nextTick,
|
||||||
|
|
@ -157,7 +159,42 @@
|
||||||
emits('showInfo', newval)
|
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() {
|
function videoPlay() {
|
||||||
|
if(isFirstPlay&&!isPlayFinish){
|
||||||
|
sendPlayStatus('start')
|
||||||
|
}
|
||||||
|
isFirstPlay=false
|
||||||
isPlying.value = true
|
isPlying.value = true
|
||||||
// #ifdef H5
|
// #ifdef H5
|
||||||
emits('controlstoggles', {
|
emits('controlstoggles', {
|
||||||
|
|
@ -183,7 +220,7 @@
|
||||||
|
|
||||||
|
|
||||||
function ended() {
|
function ended() {
|
||||||
|
Api.playStatus('end')
|
||||||
}
|
}
|
||||||
|
|
||||||
function dianzanClick() {
|
function dianzanClick() {
|
||||||
|
|
@ -270,6 +307,8 @@
|
||||||
watch(() => showVideo.value, (newval) => {
|
watch(() => showVideo.value, (newval) => {
|
||||||
console.log('showVideo change:'+newval);
|
console.log('showVideo change:'+newval);
|
||||||
if (newval) {
|
if (newval) {
|
||||||
|
isFirstPlay=true
|
||||||
|
isPlayFinish=false
|
||||||
nextTick(()=>{
|
nextTick(()=>{
|
||||||
init()
|
init()
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue