feat: add fear

This commit is contained in:
2026-05-31 20:26:03 -03:00
parent 7a1c28cd19
commit 5de127449a
9 changed files with 340 additions and 1 deletions
@@ -0,0 +1,43 @@
import { useEffect, useRef } from 'react'
interface AmbientSoundProps {
url: string
volume?: number
}
export function AmbientSound({ url, volume = 0.5 }: AmbientSoundProps) {
const audioRef = useRef<HTMLAudioElement | null>(null)
useEffect(() => {
const audio = new Audio(url)
audio.loop = true
audio.volume = volume
audioRef.current = audio
const startAudio = () => {
audio.play().catch((err) => {
console.warn('Autoplay blocked. Waiting for user interaction.', err)
})
}
startAudio()
window.addEventListener('click', startAudio, { once: true })
window.addEventListener('keydown', startAudio, { once: true })
return () => {
window.removeEventListener('click', startAudio)
window.removeEventListener('keydown', startAudio)
audio.pause()
audioRef.current = null
}
}, [url])
useEffect(() => {
if (audioRef.current) {
audioRef.current.volume = volume
}
}, [volume])
return null
}