优化播放开始请求接口增加防抖
This commit is contained in:
@@ -2,8 +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()"
|
||||
@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"
|
||||
:enable-progress-gesture="false" :poster="item.titleImg" :ref="'myVideo'+item.courseDetailsId"
|
||||
@@ -134,7 +133,7 @@
|
||||
let autoplay = ref(props.item.videoUrl ? true : false)
|
||||
|
||||
const emits = defineEmits(['controlstoggles', 'disappear', 'appear', 'waiting', 'videoPlay', 'ended', 'dianzanClick',
|
||||
'share', 'zhuijuClick', 'popupShow', 'itemMounted', 'toDetail', 'showInfo'
|
||||
'share', 'zhuijuClick', 'popupShow', 'itemMounted', 'toDetail', 'showInfo', 'playStatusChange'
|
||||
])
|
||||
|
||||
function controlstoggles(e) {
|
||||
@@ -158,43 +157,48 @@
|
||||
console.log(newval);
|
||||
emits('showInfo', newval)
|
||||
})
|
||||
|
||||
|
||||
|
||||
|
||||
//是否是第一次加载时的播放,不是暂停再播放
|
||||
let isFirstPlay=true
|
||||
let isPlayFinish=false//是否播放完成
|
||||
let isFirstPlay = true
|
||||
let isPlayFinish = false //是否播放完成
|
||||
/**
|
||||
* @param {type} = [start,end]
|
||||
*/
|
||||
function sendPlayStatus(type='start'){
|
||||
Api.playStatus({
|
||||
courseId:props.item.courseId,
|
||||
courseDetailsId:props.item.courseDetailsId,
|
||||
function sendPlayStatus(type = 'start') {
|
||||
emits('playStatusChange', {
|
||||
courseId: props.item.courseId,
|
||||
courseDetailsId: props.item.courseDetailsId,
|
||||
type
|
||||
})
|
||||
// Api.playStatus({
|
||||
// courseId:props.item.courseId,
|
||||
// courseDetailsId:props.item.courseDetailsId,
|
||||
// type
|
||||
// })
|
||||
}
|
||||
|
||||
function timeupdate(e){
|
||||
|
||||
function timeupdate(e) {
|
||||
//隐藏loding
|
||||
// #ifdef H5
|
||||
uni.hideLoading()
|
||||
// #endif
|
||||
if(isPlayFinish){
|
||||
return
|
||||
if (isPlayFinish) {
|
||||
return
|
||||
}
|
||||
if (e.detail.currentTime > e.detail.duration * 0.9) {
|
||||
if (!isFirstPlay) {
|
||||
sendPlayStatus('end')
|
||||
isPlayFinish=true
|
||||
isPlayFinish = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function videoPlay() {
|
||||
if(isFirstPlay&&!isPlayFinish){
|
||||
if (isFirstPlay && !isPlayFinish) {
|
||||
sendPlayStatus('start')
|
||||
}
|
||||
isFirstPlay=false
|
||||
isFirstPlay = false
|
||||
isPlying.value = true
|
||||
// #ifdef H5
|
||||
emits('controlstoggles', {
|
||||
@@ -304,18 +308,18 @@
|
||||
}
|
||||
})
|
||||
watch(() => showVideo.value, (newval) => {
|
||||
console.log('showVideo change:'+newval);
|
||||
console.log('showVideo change:' + newval);
|
||||
if (newval) {
|
||||
isFirstPlay=true
|
||||
isPlayFinish=false
|
||||
nextTick(()=>{
|
||||
isFirstPlay = true
|
||||
isPlayFinish = false
|
||||
nextTick(() => {
|
||||
init()
|
||||
})
|
||||
} else {
|
||||
video = null
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
|
||||
const infoStyle = computed(() => {
|
||||
return {
|
||||
@@ -328,8 +332,6 @@
|
||||
transform: `translateX(${(!isPlying.value||!props.item.videoUrl)?'0':60}px)`
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
|
||||
Reference in New Issue
Block a user