Unlike standard phone mirroring, Android Auto splits its audio streams based on intent to allow the car's head unit to handle independent volume levels, audio ducking, and specific mixing properties.
The channels being used:
Media Channel (16-bit, 44.1 kHz or 48 kHz, Stereo LPCM (Uncompressed))
Speech / Guidance Channel (16-bit, 16 kHz, Mono PCM)
Voice Command Input (16-bit, 16 kHz, Mono PCM)
1. Audio Track Separation Audit
A common mistake is piping both streams into a single player instance or using generic attributes. Your initialization must use separate AudioTrack instances mapped like this:
Music/Media Stream: Use AudioAttributes.USAGE_MEDIA and AudioAttributes.CONTENT_TYPE_MUSIC. Configure it as Stereo (CHANNEL_OUT_STEREO), matching the sample rate from the phone handshake (44.1 kHz or 48 kHz).
Guidance/Notification Stream: Use AudioAttributes.USAGE_ASSISTANCE_NAVIGATION_GUIDANCE or AudioAttributes.USAGE_NOTIFICATION. Configure it as Mono (CHANNEL_OUT_MONO) at 16 kHz.
2. Protocol Message Mapping Logic
Ensure your incoming protocol parser differentiates a temporary ducking sound from an explicit pause request sent by the phone:
AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK -> Intercept this. Do NOT fire a pause trigger to your media player thread. Instead, execute mediaTrack.setVolume(0.2f).
AUDIOFOCUS_GAIN_TRANSIENT (e.g., Voice Assistant or Phone call) -> This is an explicit pause trigger. Safely pause the media track.
4. Audio Frame Buffer Timeout (The "Tail" Check)
If notifications cut off abruptly or the music gets stuck at a quiet volume, your processing loop is missing the channel's idle state.
Implement an idle timer on the guidance channel parsing thread. If no new speech packets arrive for over 300ms to 500ms, fire a recovery function to smoothly ramp mediaTrack.setVolume(1.0f) back to full scale.