Adding audio - #62
Conversation
|
@Akshat-Raj is attempting to deploy a commit to the Genesis' projects Team on Vercel. A member of the Team first needs to authorize it. |
There was a problem hiding this comment.
Pull request overview
This PR adds audio playback to the GenesisAnimation client-side launch sequence, starting on the user’s click and synchronizing a thunder SFX with the “charge up” phase.
Changes:
- Add
useRef-managedAudioinstances for background music and thunder SFX. - Start background music on Pokéball click via a new
handleStarthandler. - Trigger thunder playback during Phase 2 and stop/reset all audio when the animation completes.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| audioRef.current.volume = 0.5; | ||
| } | ||
| if (!thunderRef.current) { | ||
| thunderRef.current = new Audio("/audio/Thunder Sound Effects Loud and Scary_320k.mp3"); |
There was a problem hiding this comment.
The thunder track path includes spaces ("/audio/Thunder Sound Effects..."). Spaces are not valid in a URL and rely on implicit encoding, which can lead to inconsistent requests/404s depending on the server/proxy. Consider renaming the file to a URL-safe name (kebab-case) and updating the path, or explicitly using an encoded URL.
| thunderRef.current = new Audio("/audio/Thunder Sound Effects Loud and Scary_320k.mp3"); | |
| thunderRef.current = new Audio("/audio/Thunder%20Sound%20Effects%20Loud%20and%20Scary_320k.mp3"); |
| // Stop all music when animation is fully over | ||
| if (audioRef.current) { | ||
| audioRef.current.pause(); | ||
| audioRef.current.currentTime = 0; | ||
| } |
There was a problem hiding this comment.
Audio is only paused/reset when the full animation completes. If the component unmounts (route change) or the async animation sequence throws/rejects partway through, the background/thunder audio can keep playing. Add a useEffect cleanup (return function) and/or wrap the run() body in try/finally so you always pause/reset audio and clear any pending timeouts when aborting.
No description provided.