Audio controls and playback automation
Audio controls and playback automation shape sound, smooth track changes, and control when playback starts or stops. They sit beside the main playback flow described in Playback system and connect to media sessions and streaming and queues and offline playback.
Audio processing
Audio processing changes decoded audio before it reaches the device. The playback service combines sound shaping, loudness control, and silence handling so user settings affect all active players.
Equalizer profiles
The equalizer applies a saved sound profile to playback. A profile can come from an imported parametric equalizer file or a user edit, and only one profile is active at a time. The profile controls frequency bands and a preamp value so listeners can tune sound for a device or preference.
The equalizer service keeps the selected profile even when a player is not ready. It applies the profile when a player becomes available and can disable it without deleting the saved profiles. This keeps the user choice across player creation and replacement.
References: app/…/EQProfileRepository.kt• L18-67 app/…/EqualizerService.kt• L30-47 app/…/EQViewModel.kt• L58-80
Loudness normalization
Loudness normalization reduces level differences between tracks. Playback uses loudness data from the selected format when it is available, then applies a gain that matches the chosen loudness target. If the source has no loudness data, normalization cannot make a reliable adjustment for that track.
Normalization is separate from the equalizer. An equalizer changes the tone, while normalization changes overall level. The player settings expose normalization and the target loudness as related controls.
References: app/…/VolumeNormalizationAudioProcessor.kt• L17-37 app/…/MusicService.kt• L3781-3795 app/…/MusicService.kt• L3884-3900 app/…/PlayerSettings.kt• L419-448
Silence skipping
Silence skipping moves playback past long quiet sections. The audio path can detect a sustained near-silent segment and notify the playback service, which then handles the skip. The normal mode detects silence for controlled skipping; instant mode enables the more direct behavior and is available only when silence skipping is on.
This feature observes audio without changing the audio stream itself. It therefore belongs to playback control rather than to sound shaping.
References: app/…/SilenceDetectorAudioProcessor.kt• L16-26 app/…/MusicService.kt• L1289-1306 app/…/PlayerSettings.kt• L376-418
Track transitions
Crossfade overlaps the end of one track with the start of the next. The settings let the listener choose whether to use crossfade, how long it lasts, and whether the transition should preserve a gapless feel. Crossfade changes the player path and disables audio offload while it is active, because the device cannot take over the full transition.
References: app/…/PlayerSettings.kt• L303-360 app/…/PlayerSettings.kt• L449-475 app/…/MusicService.kt• L1347-1359
Sleep automation
Sleep automation pauses playback after a chosen time or at a song boundary. It can also lower the volume during the final minute, which gives the listener a gradual stop instead of an abrupt pause.
Timer modes
The sleep timer supports two stop points:
- A minute-based timer pauses playback when the countdown ends.
- An end-of-song timer waits for the current media item to transition or finish.
The timer may fade the volume during its final minute. When the timer completes, it clears its state and restores the normal volume multiplier. A crossfade transition can report a song change directly so end-of-song mode still stops at the intended boundary.
References: app/…/SleepTimer.kt• L21-49 app/…/SleepTimer.kt• L51-105 app/…/SleepTimer.kt• L108-155
Automatic sleep windows
Automatic sleep windows start the default timer when playback resumes inside an allowed time range. The schedule can run daily, on weekdays, on weekends, or on selected days. Non-daily modes can use different start and end times for each day, including overnight ranges such as 22:00 to 06:00.
The playback connection checks this schedule on a paused-to-playing transition. It does not replace an already active timer, so a manual timer remains in control once started.
References: app/…/PlayerConnection.kt• L469-593 app/…/SettingsSleepTimerDialog.kt• L73-95 app/…/PlayerSettings.kt• L574-733
Music alarms
Music alarms start a playlist at a chosen clock time. Each alarm stores its own enabled state, time, playlist, and optional random-first-song behavior, so several alarms can coexist.
The alarm scheduler creates the next daily system alarm for each valid entry. At trigger time, the music service loads the playlist, optionally moves a random song to the front, replaces the current queue, and starts playback. The scheduler also restores alarms after boot, time changes, time-zone changes, or an app replacement.
flowchart LR
A[Alarm settings] --> B[Saved alarm entries]
B --> C[System alarm]
C --> D[Music service]
D --> E[Load playlist]
E --> F[Optional random first song]
F --> G[Replace queue and play]
D --> H[Schedule next occurrence]
The feature depends on Android exact-alarm and battery settings. If an alarm has no playlist, the system does not schedule it. If its playlist is empty at trigger time, the alarm is disabled instead of starting an empty queue.
References: app/…/MusicAlarmStore.kt• L20-79 app/…/MusicAlarmScheduler.kt• L11-39 app/…/MusicAlarmRescheduleReceiver.kt• L10-25 app/…/MusicService.kt• L4567-4653
Voice-directed playback
Voice-directed playback turns a spoken search request from a media controller into a local or online playback request. The session first treats an exact local playlist name as a playlist request. Otherwise, it searches songs and chooses the best title-and-artist match.
The matcher normalizes case and punctuation, removes artist words when scoring a song title, and uses fuzzy token matching for speech errors. It requires a strong enough score before selecting a song. When a song is selected, the normal playback flow can build a radio queue from it if that setting is enabled.
flowchart TD
A[Voice search request] --> B{Exact local playlist?}
B -- Yes --> C[Play playlist]
B -- No --> D[Search local and online songs]
D --> E[Rank title and artist matches]
E --> F{Strong match?}
F -- No --> G[Return no playback result]
F -- Yes --> H[Play selected song]
H --> I[Optional radio queue]
References: app/…/MediaLibrarySessionCallback.kt• L640-655 app/…/MediaLibrarySessionCallback.kt• L761-859 app/…/VoiceSearchMatcher.kt• L15-80
Playback-adjacent controls
Playback settings also control how the player uses the device and how quickly it responds to track changes. These controls affect the player as a whole rather than a single audio profile.
Device audio handoff
Audio offload lets the device handle more of the audio work. Crossfade turns it off because crossfade needs the player to process the transition. The settings show this dependency instead of allowing both modes to appear active.
Playback rate
Playback rate controls change how fast a track plays. The player settings expose varispeed as a separate playback option, while the player menu provides access to the active mode during listening.
References: app/…/PlayerSettings.kt• L449-479 app/…/PlayerExt.kt• L108-123 app/…/PlayerMenu.kt• L80-145
Change checklist
When these files or sections are changed, remember to consider these:
- Changes to alarm fields must stay aligned across stored entries, pending-intent extras, trigger handling, and next-occurrence scheduling.
- Changes to sleep-window formats must stay aligned between the settings dialog and the playback connection that reads the schedule.
- Changes to audio processor creation must preserve profile, normalization, and silence state when the playback service creates or replaces a player.
- Changes to voice-search selection must preserve the distinction between an exact local playlist request and a song match.
- Changes to crossfade must keep its audio-offload constraint visible in both settings and player configuration.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| An alarm has no playlist or its playlist is empty | The alarm cannot start useful playback; an empty triggered alarm is disabled | Scheduler skips blank playlist IDs, and the service disables an alarm with no songs |
| Android exact-alarm access or battery exceptions are not granted | The alarm may run later than its target time or be stopped by the system | Alarm settings surface both system conditions and the scheduler falls back to an inexact idle-safe alarm |
| A sleep window has an invalid time string | Automatic sleep start is skipped | The schedule check catches parse errors and returns without starting a timer |
| A voice query is too short or has no strong song match | No song is selected for playback | The matcher rejects generic queries and requires the strong-match threshold |
| An EQ profile is applied before a player is ready | The sound change is not lost, but it is delayed | The equalizer service keeps a pending profile and applies it when a processor is added |
Key files
| File | Why to read it |
|---|---|
| app/…/MusicService.kt | Main playback owner for audio processors, alarms, and queue starts |
| app/…/SleepTimer.kt | Timer states, fade-out behavior, and stop boundaries |
| app/…/PlayerConnection.kt | Automatic sleep-window checks during playback state changes |
| app/…/EqualizerService.kt | Profile application across active and future players |
| app/…/EQProfileRepository.kt | Saved profile and active-profile lifecycle |
| app/…/MusicAlarmScheduler.kt | System alarm creation, cancellation, and rescheduling |
| app/…/MusicAlarmStore.kt | Alarm data and persistence boundary |
| app/…/MediaLibrarySessionCallback.kt | Media-controller and voice-request to playback mapping |
| app/…/VoiceSearchMatcher.kt | Song match ranking for voice-directed playback |
| app/…/PlayerSettings.kt | User-facing settings for audio and sleep behavior |
| app/…/AlarmSettings.kt | User-facing alarm lifecycle and scheduling entry point |