feat(directory): handle voice on and off correctly

This commit is contained in:
Haoyu Xu
2023-03-03 16:57:59 -05:00
parent 18eb1371c6
commit 1c0f425c9a
4 changed files with 18 additions and 3 deletions

View File

@@ -1 +1 @@
0.5.29
0.5.30

View File

@@ -51,11 +51,15 @@ export default function useAudio() {
}, [])
const getSrc = useCallback(() => audioEl.src, [])
const resetSrc = useCallback(() => {
audioEl.src = ''
}, [])
return {
play,
stop,
getSrc,
resetSrc,
isPlaying,
isPlayingRef,
}

View File

@@ -88,13 +88,20 @@ export default function Home() {
function OperatorElement({ item, hidden }) {
const { textDefaultLang, language, alternateLang } = useLanguage()
const { play } = useAudio()
const { play, stop, resetSrc } = useAudio()
const [voiceOn] = useAtom(voiceOnAtom)
const playVoice = useCallback(() => {
if (!voiceOn) return
play(`/${item.link}/assets/${JSON.parse(import.meta.env.VITE_VOICE_FOLDERS).main}/${import.meta.env.VITE_APP_VOICE_URL}`)
}, [play, item.link, voiceOn])
}, [voiceOn, play, item.link])
useEffect(() => {
if (!voiceOn) {
stop()
resetSrc()
}
}, [voiceOn, stop, resetSrc])
return useMemo(() => {
return (

View File

@@ -91,6 +91,10 @@ export default function Operator() {
stop()
}, [setExtraArea, stop])
useEffect(() => {
if (!voiceLang) stop()
}, [stop, voiceLang])
useEffect(() => {
if (backgrounds) setCurrentBackground(backgrounds[0])
}, [backgrounds])