|
@@ -34,7 +34,7 @@ export default defineComponent({
|
|
|
const controlID = 'v' + Date.now() + Math.floor(Math.random() * 100)
|
|
|
const playBtnId = 'play' + Date.now() + Math.floor(Math.random() * 100)
|
|
|
const loopBtnId = 'loop' + Date.now() + Math.floor(Math.random() * 100)
|
|
|
-
|
|
|
+
|
|
|
const togglePlay = (e: Event) => {
|
|
|
e.stopPropagation()
|
|
|
if (!data.videoContianerRef.paused) {
|
|
@@ -66,11 +66,11 @@ export default defineComponent({
|
|
|
})
|
|
|
document.getElementById(playBtnId)?.addEventListener('click', togglePlay)
|
|
|
document.getElementById(loopBtnId)?.addEventListener('click', toggleLoop)
|
|
|
- setName();
|
|
|
+ setName()
|
|
|
}
|
|
|
const setName = () => {
|
|
|
- const nameEl = document.getElementById('videoItemName');
|
|
|
- if (nameEl){
|
|
|
+ const nameEl = document.getElementById('videoItemName')
|
|
|
+ if (nameEl) {
|
|
|
nameEl.innerHTML = item.value.name || ''
|
|
|
}
|
|
|
}
|
|
@@ -133,13 +133,34 @@ export default defineComponent({
|
|
|
const toggleHideControl = (isShow: boolean) => {
|
|
|
data.videoItem?.toggleControls(isShow)
|
|
|
}
|
|
|
- watch(() => props.activeModel, () => {
|
|
|
- toggleHideControl(props.activeModel)
|
|
|
- })
|
|
|
+ watch(
|
|
|
+ () => props.activeModel,
|
|
|
+ () => {
|
|
|
+ toggleHideControl(props.activeModel)
|
|
|
+ }
|
|
|
+ )
|
|
|
|
|
|
- watch(() => props.item, () => {
|
|
|
- setName();
|
|
|
- })
|
|
|
+ watch(
|
|
|
+ () => props.item,
|
|
|
+ () => {
|
|
|
+ setName()
|
|
|
+ }
|
|
|
+ )
|
|
|
+ let videoTimer = null as any
|
|
|
+ const handlePlayVideo = () => {
|
|
|
+ clearTimeout(videoTimer)
|
|
|
+ nextTick(() => {
|
|
|
+ data.videoContianerRef.play().catch((err) => {
|
|
|
+ console.log("🚀 ~ err:", err)
|
|
|
+ videoTimer = setTimeout(() => {
|
|
|
+ if (err?.message?.includes('play()')) {
|
|
|
+ emit('play')
|
|
|
+ }
|
|
|
+ handlePlayVideo();
|
|
|
+ }, 1000)
|
|
|
+ })
|
|
|
+ })
|
|
|
+ }
|
|
|
|
|
|
return () => (
|
|
|
<div class={styles.videoWrap}>
|
|
@@ -153,9 +174,7 @@ export default defineComponent({
|
|
|
onLoadedmetadata={() => {
|
|
|
data.videoState = 'pause'
|
|
|
changePlayBtn('play');
|
|
|
- nextTick(() => {
|
|
|
- data.videoContianerRef.play();
|
|
|
- })
|
|
|
+ handlePlayVideo();
|
|
|
}}
|
|
|
onPlay={() => {
|
|
|
console.log('开始播放')
|