Overview
The audio utilities provide functions for playing audio files from Praydo’s bundled assets. These are used for adhan (call to prayer) and notification sounds.playSound
Plays an audio file from the application’s asset bundle.Parameters
The name of the audio file to play (must be located in the
assets/ directory)Returns
A promise that resolves when the audio starts playing (not when it finishes)
Available Audio Files
Praydo includes three audio files in theassets/ directory:
| File | Description | Usage |
|---|---|---|
adhan-fajr.mp3 | Fajr (dawn) adhan | Played at Fajr time when adhan is enabled |
adhan-makkah.mp3 | Standard adhan (Makkah style) | Played at Dhuhr, Asr, Maghrib, and Isha when adhan is enabled |
solemn.mp3 | Subtle notification tone | Played when adhan is disabled or for pre-prayer notifications |
Example
Implementation Details
The function:- Reads the audio file from the Tauri resource directory using
@tauri-apps/plugin-fs - Creates a Blob from the file data with MIME type
audio/mpeg - Generates an object URL for the Blob
- Creates an HTML5 Audio element
- Calls
.play()on the audio element
Audio files are bundled with the application in the
src-tauri/assets/ directory and packaged as resources in the final build.Usage in Notifications
ThePrayerManager uses playSound() when sending notifications:
Pre-prayer notifications (N minutes before):
Platform Support
Audio playback works across all platforms:- Windows: Uses native WebView2 audio
- macOS: Uses WebKit audio
- Linux: Uses WebKitGTK audio
The audio plays using the system’s default audio output. Volume is controlled by the system volume settings.
Error Handling
The function does not explicitly handle errors. If the audio file is missing or playback fails, the promise will reject. In production, you may want to wrap calls in try/catch:Asset Management
To add new audio files:- Place MP3 files in
src-tauri/assets/ - Ensure they’re included in the bundle configuration in
tauri.conf.json: - Call
playSound('your-file.mp3')