Audio services
The app uses two foreground services for audio playback:- AdhanPlaybackService - Plays Adhan at prayer times
- QuranAudioService - Streams or plays downloaded Quran recitations
- Notification controls (play, pause, stop)
- Background playback
- Audio focus management
- Lock screen controls
AdhanPlaybackService
Foreground service that plays Adhan sounds when prayer notifications trigger. Source:data/audio/AdhanPlaybackService.kt
Features
- Automatic playback when prayer time arrives
- Volume management (uses alarm stream for reliability)
- Wake lock to ensure playback completes
- Notification controls to stop adhan
- Vibration pattern during playback
- Audio focus handling (pauses other audio)
Starting adhan playback
Adhan sounds
Four adhan sound options:data/audio/AdhanSound.kt
Service lifecycle
Service started
When prayer time arrives,
BootReceiver starts AdhanPlaybackService with the configured adhan sound.Notification controls
The foreground notification includes:- Prayer name and time
- Stop button (PendingIntent)
- Tap to open app action
AdhanDownloadService
Foreground service for downloading adhan audio files. Source:data/audio/AdhanDownloadService.kt
Features
- Background downloads with progress notification
- Storage management in app-specific directory
- Download verification (checks file size and integrity)
- Automatic default download on first app launch
Starting a download
Default download on first launch
InNimazApp.onCreate():
NimazApp.kt:98-111
AdhanAudioManager
Manages adhan file storage and verification. Source:data/audio/AdhanAudioManager.kt
Methods
Storage location
Adhan files are stored in:QuranAudioService
Foreground service for Quran recitation playback. Source:data/audio/QuranAudioService.kt
Features
- Streaming audio from online sources
- Local playback for downloaded recitations
- Surah or ayah range playback
- Playback controls (play, pause, seek, next, previous)
- Repeat modes (single ayah, surah, all)
- Playback speed adjustment
- Media session integration for lock screen and notification controls
Starting Quran playback
Available reciters
Quran audio sources from EveryAyah.com:- Abdul Rahman Al-Sudais (
ar.abdurrahmanalsudais) - Mishary Rashid Alafasy (
ar.misharyalafasy) - Abdul Basit (
ar.abdulbasitmurattal) - And more…
Media session controls
The service exposes standard media controls:- Play/Pause
- Skip to next ayah
- Skip to previous ayah
- Seek within ayah
- Stop playback
- Notification
- Lock screen
- Android Auto
- Wear OS
Audio focus management
Both services request audio focus to ensure:- Only one audio stream plays at a time
- Other apps pause when adhan/Quran plays
- Playback resumes after interruptions (like phone calls)
Dependencies
Audio playback uses Media3 (ExoPlayer):app/build.gradle.kts:108-111
Best practices
Always use foreground services for audio
Always use foreground services for audio
Android requires foreground services for background audio playback. Both services display persistent notifications.
Request audio focus before playback
Request audio focus before playback
Ensures your audio doesn’t conflict with other apps and system sounds.
Handle interruptions gracefully
Handle interruptions gracefully
Implement audio focus change listeners to pause/resume on phone calls or notifications.
Use wake locks for adhan
Use wake locks for adhan
Adhan playback uses PARTIAL_WAKE_LOCK to ensure audio plays even if screen is off.
Clean up resources
Clean up resources
Release ExoPlayer, media session, and wake locks in service onDestroy().