Video Capture - Allow users to select a bluetooth mic as an audio input source

38 views
Skip to first unread message
Assigned to mingd...@google.com by wuj...@google.com

Aubrey Haskett

unread,
Aug 20, 2024, 11:00:11 AMAug 20
to Android CameraX Discussion Group
Hi CameraX Devs, 

Searched the threads and didn't see anyone else ask this yet...

A while ago, I asked if we could change the audio input source and the answer was yes, via reflection (link to convo).

Now I'm wondering if there is a similar, back-door way to change the mic? I'm specifically looking to allow users to select a bluetooth mic to use if they'd like. Open to a front-door way as well but I don't see one. :) 

I have tried setting audioManager.setCommunicationDevice() to use AudioDeviceInfo.TYPE_BLUETOOTH_SCO before I changed my audioSource via reflection, but found the recording still used the device mic.

Thanks,
Aubrey

Ming-Da Tsai

unread,
Aug 22, 2024, 6:22:06 AMAug 22
to Android CameraX Discussion Group, aubrey....@gc.com
Hi,

I tested this locally on a Pixel 8 Pro with Bluetooth earbuds, and it's working for me. I configured CameraX to use the MIC as the audio source, and set the audio output to the TYPE_BLUETOOTH_SCO device using AudioManager.setCommunicationDevice() (within onResume()). This successfully recorded audio from the Bluetooth earbuds. I also tried the deprecated setBluetoothScoOn() method, which worked as well.

Under the hood, CameraX utilizes AudioRecord for audio recording, so the configuration CameraX could change is only AudioRecord.Builder#setAudioSource().

Could you please share the device model and build you're testing on, along with a relevant code snippet? This will help in understanding any potential discrepancies. Thank you.

By the way, if you're using the latest version of CameraX, you can directly set the audio source using Recorder.Builder().setAudioSource(MIC) instead of using reflection. However, you might still need to suppress some lint warnings as this method is currently internal, and the MIC constant isn't officially added.

Best regards,
Ming-Da
Reply all
Reply to author
Forward
0 new messages