|
@@ -13,6 +13,8 @@ const props = defineProps({
|
|
|
},
|
|
|
})
|
|
|
|
|
|
+const emits = defineEmits(['scoreAtTarget'])
|
|
|
+
|
|
|
const videoPlayerRef = shallowRef()
|
|
|
const player = ref()
|
|
|
|
|
@@ -28,6 +30,8 @@ function getSourceType(src: string) {
|
|
|
}
|
|
|
|
|
|
onMounted(() => {
|
|
|
+ if (!videoPlayerRef.value)
|
|
|
+ return
|
|
|
player.value = videojs(
|
|
|
videoPlayerRef.value as HTMLVideoElement,
|
|
|
{
|
|
@@ -40,7 +44,7 @@ onMounted(() => {
|
|
|
'PlayToggle', // 播放
|
|
|
'NextBtn', // 下一个
|
|
|
'CurrentTimeDisplay', // 当前时间
|
|
|
- 'ProgressControl', // 进度条
|
|
|
+ // 'ProgressControl', // 进度条
|
|
|
'DurationDisplay', // 时长
|
|
|
'VolumePanel', // 音量
|
|
|
'PlaybackRateMenuButton', // 倍速
|
|
@@ -57,13 +61,27 @@ onMounted(() => {
|
|
|
},
|
|
|
() => {
|
|
|
console.log('player is ready')
|
|
|
+ const p = player.value
|
|
|
+ let callbackExecuted = false
|
|
|
+ p.on('timeupdate', () => {
|
|
|
+ // 计算视频已经播放的百分比
|
|
|
+ const percentagePlayed = p.currentTime() / p.duration()
|
|
|
+
|
|
|
+ if (percentagePlayed >= 0.9 && !callbackExecuted) {
|
|
|
+ // 执行回调函数
|
|
|
+ console.log('达到目标时间')
|
|
|
+ emits('scoreAtTarget')
|
|
|
+ p.off('timeupdate')
|
|
|
+ callbackExecuted = true
|
|
|
+ }
|
|
|
+ })
|
|
|
},
|
|
|
)
|
|
|
})
|
|
|
|
|
|
onUnmounted(() => {
|
|
|
if (player.value)
|
|
|
- player.value.dispose()
|
|
|
+ player.value?.dispose?.()
|
|
|
})
|
|
|
</script>
|
|
|
|