fix sound
This commit is contained in:
35
src/App.jsx
35
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);
|
||||
|
||||
Reference in New Issue
Block a user