I have a Bluetooth headset (BTC6White). I want to speak into the microphone and an Android device play the sound.
So, How I can do this? First, I can establish a socket connection
socket = mDevice.createRfcommSocketToServiceRecord(UUID.fromString("0000111e-0000-1000-8000-00805f9b34fb"));
socket.connect();
Then, how I get the audio? What is the use this method: startBuetoothSco? To put the audio in the speaker, Should I use Auditrack?
int buffersize = AudioTrack.getMinBufferSize(8000, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_8BIT);
soundData = new byte [buffersize*5];
audioTrack = new AudioTrack(AudioManager.STREAM_VOICE_CALL,
8000, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_8BIT,
soundData.length,AudioTrack.MODE_STREAM);
But, then, Should I fill the buffer soundData? How? Using the socket (into a Thread)?
mmInStream = socket.getInputStream();
public void run() {
byte[] buffer = new byte[8000*2];
while (true) {
bytes = mmInStream.read(buffer);
audioTrack.write(buffer, 0, bytes); //write directly?
}}
And startBuetoothSco() for what? To know sco states? SCO_AUDIO_STATE_CONNECTED... Or to send/receive data? I don't understand how get de audio data from de headset and then how to streaming to the speaker. It's necessary establish a SCO connection (with AudioManager) to get the data of the bluetooth headset?
It's very difficult find information about this problem and the android documentation is very poor (this topic).