The Sound service provides audio feedback for user interactions, primarily QR code scanning. It uses expo-av to load and play a beep sound, with graceful degradation if audio resources are unavailable.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Diego31-10/TableOrderApp/llms.txt
Use this file to discover all available pages before exploring further.
Configuration
The service uses a remote audio file during development:For production, replace the remote URI with a local asset:This eliminates network dependency and reduces bundle size once you have the asset.
Functions
preloadBeep
Preloads the beep sound for instant playback. Should be called once during app startup.Returns void. Failures are silently caught to prevent app crashes.
Example
Behavior
-
Sets audio mode to play in silent mode on iOS:
-
Creates and caches the sound instance:
-
Errors are caught silently (graceful degradation):
playBeep
Plays the preloaded beep sound. If not preloaded, attempts lazy loading on first call.Returns void. Failures are silently caught to avoid disrupting the scan flow.
Example
Behavior
-
Checks if sound is preloaded, lazy-loads if not:
-
Resets playback position to start:
-
Plays the sound:
-
All errors are silently caught:
unloadBeep
Releases the Audio.Sound resource. Should be called on app unmount.Returns void. Errors are silently caught.
Example
Behavior
-
Unloads the sound instance and clears memory:
-
Errors are caught silently:
Sound instance management
The service maintains a module-level singleton:- Only one sound object is loaded in memory
- Subsequent
playBeep()calls reuse the same instance - Multiple rapid calls won’t create audio resource leaks
Graceful degradation
The service is designed to never crash the app:- Network failures: Remote URI loading fails silently
- Missing assets: Local file not found fails silently
- Audio permissions: iOS audio restrictions fail silently
- Resource exhaustion: Memory/CPU limits fail silently
iOS silent mode
The service explicitly enables playback in silent mode:Volume control
The sound is preloaded at 80% volume:Best practices
-
Preload early: Call
preloadBeep()in RootLayout for instant first-play -
Don’t await playback: Fire and forget for responsive UI
- Test on device: Audio doesn’t work reliably in simulators
-
Pair with haptics: Audio alone may not be perceived (silent mode, hearing impairment)
- Unload on unmount: Prevent memory leaks in long-running apps
Common patterns
QR scanner feedback
Payment confirmation
Button press enhancement
Troubleshooting
Sound doesn’t play
- Check device volume (physical buttons)
- Verify audio mode on iOS (should play in silent mode)
- Test with headphones connected
- Check console for silent error logs
- Verify network connection (if using remote URI)
Sound plays with delay
- Ensure
preloadBeep()was called during app initialization - Check network latency (if using remote URI)
- Switch to local asset for zero-latency playback
Memory warnings
- Ensure
unloadBeep()is called on app unmount - Check for multiple sound instances (should only be one)
- Verify cleanup in useEffect return functions