From 350b32e87fee68bbc0a2b61560c7e31496e5e4b2 Mon Sep 17 00:00:00 2001 From: syui Date: Sat, 7 Mar 2026 22:01:30 +0900 Subject: [PATCH] fix sound --- src/App.jsx | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/src/App.jsx b/src/App.jsx index 996c837..f8d1fdf 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -35,8 +35,32 @@ export default function App() { return onAdminChange((v) => setIsAdmin(v)); }, []); + // Background wind sound loop + const windRef = useRef(null); + useEffect(() => { + const wind = new Audio(`${import.meta.env.BASE_URL}sound/wind.mp3`); + wind.loop = true; + wind.volume = volumeRef.current; + wind.play().catch(() => {}); + windRef.current = wind; + return () => { wind.pause(); wind.src = ''; }; + }, []); + const handleLangChange = useCallback((v) => { setLang(v); langRef.current = v; }, []); - const handleVolumeChange = useCallback((v) => { setVolume(v); volumeRef.current = v; }, []); + const handleVolumeChange = useCallback((v) => { + setVolume(v); + volumeRef.current = v; + if (windRef.current) windRef.current.volume = v; + }, []); + + useEffect(() => { + if (!windRef.current) return; + if (view === 'nasa') { + windRef.current.pause(); + } else { + windRef.current.play().catch(() => {}); + } + }, [view]); const playSkillVoice = useCallback(() => { const type = voicePattern[voiceIndexRef.current % voicePattern.length]; @@ -130,7 +154,14 @@ export default function App() { playAnim('burst'); // Sky: sunset → night during burst setBurstSky(new Date('2024-06-21T17:30:00')); - setTimeout(() => setBurstSky(null), 4500); + if (windRef.current) { windRef.current.pause(); } + const burstSound = new Audio(`${import.meta.env.BASE_URL}sound/burst.mp3`); + burstSound.volume = volumeRef.current; + burstSound.play().catch(() => {}); + setTimeout(() => { + setBurstSky(null); + if (windRef.current) { windRef.current.play().catch(() => {}); } + }, 4500); const suffix = langRef.current === 'en' ? '_en' : ''; const file = `${import.meta.env.BASE_URL}voice/ai/burst_1${suffix}.mp3`; const audio = new Audio(file);