Overview
Aradia uses two classes for audio handling:AudioHandlerProvider- Provider wrapper for initializing the audio serviceMyAudioHandler- Core audio playback implementation
lib/resources/services/audio_handler_provider.dartlib/resources/services/my_audio_handler.dart
AudioHandlerProvider
AChangeNotifier that wraps MyAudioHandler and manages initialization.
initialize
Initializes the audio service with Android notification configuration. Returns:Future<void>
Example:
audioHandler
Getter that returns the initializedMyAudioHandler instance.
Returns: MyAudioHandler
MyAudioHandler
ExtendsBaseAudioHandler from audio_service package to provide full-featured audio playback.
initSongs
Initializes the audio queue with audiobook files and prepares playback.List of audio files to play
Audiobook metadata
Track index to start playback (0-based)
Starting position within the track in milliseconds
Future<void>
This method:
- Builds
MediaItemqueue for notification display - Creates
AudioSourcelist (supports YouTube, local files, and remote URLs) - Handles chapter-based clipping using
ClippingAudioSource - Configures audio session for music playback
- Loads audiobook to ChromeCast if connected
- Persists state to Hive for resume capability
play
Starts or resumes playback. Routes to ChromeCast if connected. Returns:Future<void>
Example:
pause
Pauses playback and saves current position. Returns:Future<void>
Example:
stop
Stops playback completely and persists final state. Returns:Future<void>
seek
Seeks to a specific position in the current track.Target position to seek to
Future<void>
Example:
skipToNext
Skips to the next track in the queue. Returns:Future<void>
skipToPrevious
Skips to the previous track in the queue. Returns:Future<void>
skipToQueueItem
Jumps to a specific track in the queue.Queue index to jump to
Future<void>
Example:
fastForward
Seeks forward by 15 seconds. Returns:Future<void>
rewind
Seeks backward by 10 seconds. Returns:Future<void>
setSpeed
Sets playback speed.Playback speed multiplier (e.g., 1.0 = normal, 1.5 = 1.5x speed)
Future<void>
Example:
setVolume
Sets the playback volume.Volume level from 0.0 (mute) to 1.0 (max)
Future<void>
setSkipSilence
Enables or disables silence skipping.Whether to skip silent sections
Future<void>
getPositionStream
Returns a stream of position updates for progress tracking. Returns:Stream<PositionData>
Example:
Audio Effects (Android)
setEqualizerBand
Sets the gain level for a specific equalizer band (Android only).Band index: 0 (60Hz), 1 (230Hz), 2 (910Hz), 3 (4kHz), 4 (14kHz)
Gain in decibels, clamped to -15.0 to +15.0 dB
Future<void>
Example:
setEqualizerEnabled
Enables or disables the equalizer (Android only).Whether to enable the equalizer
Future<void>
setBalance
Sets the left/right audio balance.Balance from -1.0 (left) to +1.0 (right), 0.0 = center
Future<void>
setPitch
Adjusts the audio pitch without changing speed.Pitch multiplier (e.g., 1.0 = normal pitch)
Future<void>
setLoudnessEnhancer
Sets the loudness enhancer gain (Android only).Target gain in millibels, clamped to 0.0-1000.0
Future<void>
Example:
getEqualizerParameters
Retrieves current equalizer parameters (Android only). Returns:Future<AndroidEqualizerParameters?>
Utility Methods
getCurrentAudiobookId
Returns the identifier of the currently playing audiobook. Returns:String?
getAudioSourcesFromPlaylist
Returns the list of audio sources in the current queue. Returns:List<AudioSource>
restoreIfNeeded
Restores the playback queue from Hive storage on cold start without auto-playing. Returns:Future<void>
Example:
ChromeCast Support
The audio handler integrates withChromeCastService via the chromeCastService getter. When a ChromeCast device is connected, playback commands are automatically routed to the cast device.
Access ChromeCast service:
Persistence
Playback state is automatically saved to Hive (playing_audiobook_details_box) including:
- Current audiobook and files
- Track index and position
- Playback history
- Every 10 seconds during playback
- When changing tracks
- On pause/stop operations