We try to adapt our navigator application for Android Automotive OS and we see that if we use STREAM_MUSIC
for navigator notifications then it doesn't mix with FM-radio.
If we use STREAM_NOTIFICATION
then navi does mix with FM-radio, but there is no way in Android Car Settings to change STREAM_NOTIFICATION
volume.
Do we understand correctly that streams doesn't map to AudioAttributes in Automotive OS automatically and all navigator applications will have to move to USAGE_ASSISTANCE_NAVIGATION_GUIDANCE
to run properly on Automotive OS?

- 374
- 4
- 14
-
I've found that "Android automotive implementations should control volume using a hardware amplifier instead of a software mixer. " So it seems that AudioManager does software mixing internally and that's somehow hard to support hardware amplifier in terms of existing and deprecated streams API in AudioManager? https://source.android.com/devices/automotive/audio/audio-control#configure-volume – vrfloppa Oct 30 '19 at 16:00
1 Answers
You should use usage and content audio attributes in your application instead of legacy stream types.
Stream types like STREAM_MUSIC
, STREAM_NOTIFICATION
, etc. are superseded by AudioAttributes for defining the behavior of audio playback and most of the stream-based API is already deprecated - one exception in regular Android is volume control (refer to AudioManager and methods like setStreamVolume
, adjustStreamVolume
, etc.).
But in Android Automotive implementations the Android Framework is configured to use fixed volume policy which means there's also no stream-based volume control. Actual volume control is expected to be realized by Audio HAL or hardware amplifier (refer to Android Automotive Audio documentation) and for such case there's a separate volume control API based on volume groups in CarAudioManager.
Please also remember that before starting an audio stream, the application should request audio focus using the same audio attributes as it will use for its audio stream.
Simplified example:
AudioAttributes playbackAttributes = new AudioAttributes.Builder()
.setUsage(AudioAttributes.USAGE_MEDIA)
.setContentType(AudioAttributes.CONTENT_TYPE_MUSIC)
.build();
MediaPlayer player = new MediaPlayer();
player.setDataSource( /* ... */);
player.setAudioAttributes(playbackAttributes);
player.prepare();
AudioFocusRequest focusRequest = new AudioFocusRequest.Builder(AudioManager.AUDIOFOCUS_GAIN)
.setAudioAttributes(playbackAttributes)
.setOnAudioFocusChangeListener( /* ... */)
.build();
int result = mAudioManager.requestAudioFocus(focusRequest);
if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
// Respect audio focus
player.start();
}

- 76
- 3
-
Thanks for detailed reply! In my opinion it's quite unusual that in this case deprecated means "not supported at all" https://source.android.com/devices/audio/attributes#deprecated I thought that it's possible to map stream types to AudioAttributes the same way as they are getting mapped in https://github.com/Rayduh/support/blob/master/media-compat/java/android/support/v4/media/AudioAttributesCompat.java#L702 – vrfloppa Nov 19 '19 at 13:40