diff --git a/src/pages/index/components/question.vue b/src/pages/index/components/question.vue index 79177816..324abf97 100644 --- a/src/pages/index/components/question.vue +++ b/src/pages/index/components/question.vue @@ -68,7 +68,7 @@ activeVoiceId, dataInfo } = toRefs(props) - + const storageStore = useStorageStore(); const emit = defineEmits(['changePlay']) watch(() => props.dataInfo, () => {}, { @@ -112,6 +112,7 @@ emit('changePlay', unref(dataInfo)?.id) console.log(unref(dataInfo)?.id) + isPlaying.value = true if (talkVoiceObj.value && talkVoiceObj.value.src) { console.log(1, talkVoiceObj.value.src) setTimeout(() => { @@ -133,7 +134,7 @@ voiceLoading.value = false; itemVoice.value = url; talkVoiceObj.value.src = url; - if(unref(dataInfo)?.id !== props.activeVoiceId) return + if (unref(dataInfo)?.id !== props.activeVoiceId) return talkVoiceObj.value.play(); } else { downloadFile(unref(dataInfo).bucketKey) @@ -145,29 +146,32 @@ voiceLoading.value = false; itemVoice.value = res.tempFilePath; talkVoiceObj.value.src = res.tempFilePath; - if(unref(dataInfo)?.id !== props.activeVoiceId) return + if (unref(dataInfo)?.id !== props.activeVoiceId) return talkVoiceObj.value.play(); storageStore.setStorage('audio', unref(dataInfo).bucketKey, itemVoice.value); }) .catch((err) => { + isPlaying.value = false voiceLoading.value = false; emit('changePlay', ''); }); } }); } - - + + } const initVoice = () => { console.log('init') talkVoiceObj.value = uni.createInnerAudioContext() talkVoiceObj.value.onEnded(() => { emit('changePlay', '') + isPlaying.value = false // talkVoiceObj.value.src = '' }) talkVoiceObj.value.onError((err) => { console.log(err) + isPlaying.value = false talkVoiceObj.value.src = '' }) // if (unref(dataInfo).intrctWay === '02') { @@ -241,7 +245,6 @@ immediate: true } ) -