Google is committed to advancing racial equity for Black communities. See how.

HwAudioSource Player

HwAudioSource connects the audio source device directly to an Android mixer.


Several limitations may arise when using a device-to-device or hardware audio patch with Android. These are unable to receive media key events such as PLAY, PAUSE, and STOP and, because they circumvent Android's audio stack, they require hardware to mix the patch into other audio from Android.

Using HwAudioSource

HwAudioSource is a new type of player designed as a software patch. This enables applications that use this player to receive media key events and the output stream to be mixed and routed by Android.

mHwAudioSource = new HwAudioSource.Builder()
                .setAudioDeviceInfo(AudioDeviceInfo: info)
                .setAudioAttributes(new AudioAttributes.Builder()

Changes to the audio HAL

With this new player, there are a couple of expectations for the audio HAL (for example, device/generic/car/emulator/audio/driver/audio_hw.c):

  • Adev_create_audio_patch expects the request to establish an audio patch from a device to a mixer. This does not require anything special.
  • Adev_open_input_stream expects the audio_source to be AUDIO_SOURCE_FM_TUNER
  • In_read fill the audio buffer with actual broadcast radio audio data

It is recommended to configure a tuner device with type AUDIO_DEVICE_IN_FM_TUNER in audio_policy_configuration.xml:


With this device configuration, finding the FM radio input device can be facilitated by using the AudioManager.getDevices(AudioManager.GET_DEVICES_INPUTS) in conjunction with AudioDeviceInfo.TYPE_FM_TUNER.