Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Streaming audio between external bluetooth device and Android phone

I'm considering building an Android app that allows for streaming audio via bluetooth to and from the Android phone. I've read similar questions on Stackoverflow before, and based on my understanding, A2DP cannot be used as Android can't become an A2DP sink.

In theory, I believe that a profile such as HFP or HFP AG should allow for bidirectional audio streams. In the Android API, is there a way to force a bluetooth pairing to follow this profile, or does the OS decide which profile to use (such as forcing HFP only when there's a phone call going on)?

like image 907
Rahin Avatar asked Jun 12 '15 05:06

Rahin


1 Answers

I've been able to achieve what I wanted using RFCOMM-based SPP. In order to send audio to the external device, I use the AudioRecord API to record PCM-16 audio to stream audio realtime over Bluetooth. In order to receive audio, I spawn a thread that is responsible for outputting audio to the speaker using the AudioTrack API (in streaming mode)

like image 175
Rahin Avatar answered Oct 21 '22 22:10

Rahin