Bluetooth audio streaming between android devices - android

I made a research on the same topic and found that android devices are a2dp sources and the audio can be streamed only from an a2dp source to an a2dp sink. A2dp sink can be a bluetooth headset or a bluetooth speaker.
But my question is then how the android app named "Bluetooth Music Player" works?
It allows streaming from one mobile to another. So in this case the listening mobile device must act as a sink. How this is possible?
Are they using some other profile instead of a2dp?
Ok, that may be a different profile what they are using. Because the application needs to be installed in the client side also.
But how it becomes possible to stream voice from a bluetooth microphone to an android device?
Please help.

Without knowing details about the mentioned Bluetooth Music Player, it seems to use simple Bluetooth data connection, otherwise you would not need to install a client on playing/sending device.
To stream audio from microphone to another device, you can record it on your sending device and send it to the receiving device. You will need to implement a protocol for that purpose.
OR
You can implement an alternative A2DP sink service. This is, what the sink is: a device with a Bluetooth Protocol Stack with an implementation of A2DP Sink.
Edit:
For the case you detailed by your comments, the sending device should be left as-is, without installing any app. That implicitly means that your solution must make use of out-of-the-box Bluetooth functionality of that Android device.
What you can use here is therefor limited to those profiles that Android typically support, which is HSP, HFP and A2DP. Since you obviously want to stream music, A2DP would be your choice.
On the device supposed to receive the audio stream and do the playback, you have to implement a service providing the A2DP sink as an self implemented BluetoothService opening a BluetoothServerSocket on RFCOMM as described in Android documentation.
You will have to spend much effort implementing this, and I am not sure if you will need a license for this.

Related

Android sending message to BLE A2DP device

I have a device (ESP32) that has a Bluetooth module. I found some library to use on it and it acts as A2DP sink, works perfectly with Spotify app. My objective is to be able to send some small packages of data to it from my Android phone (device name, notifications, etc) while Spotify app is streaming media to it. What would be the best way of doing that? I tried to approach this with MediaSession.setMetadata method, but it seems it only works with actual media playback.

BLE audio as microphone input on Android

I am developing a custom hardware (peripheral) device that will communicate with Android smartphones through BLE. This device will have several capabilities, including the transmission of audio through GATT and keypresses through HID.
Is it somehow possible to re-route the BLE audio input to the Android OS if it was the internal device microphone? For instance, so that we could make voice searches using the default Google app, using the microphone on this external device. Can it be done without rooting the device, writing custom drivers or customize the kernel?
I found several similar threads on SO, but none with a specific solution for this issue (e.g., An extensive project: Streaming audio from microphone to Android device)
Thanks in advance!
It can be done. This is how I did it:
Have a service that talks to BLE Remote device and receives audio
Create a Audio HAL that implements an audio input.
Modify Audio Policy manager to use your HAL for Voice-recognition inputs
Send audio data from Service to HAL over any available IPC (I use socket)
Done.
There are other ways too. e.g. you could allow regular pairing but then intercept all audio messages from your device in fluoride and forward them to your, or A2DP HAL etc.

Bluetooth : Transferring call from Source to sink?

I have one android phone (Samsung S Duos) that will act as SOURCE and one Audio Development Kit i.e. CSR 8670 which will Act as SINK. I am trying to activate the a2dp profile and than transferring the incoming call of my phone (Samsung S Duos) to the Kit(CSR 8670) but not able to achieve it. Please assist me to overcome this problem.
A2DP uses ACL packets, voice calls (handsfree) uses SCO packets over the air.
The "Call" audio runs over SCO channel, so it is "technically" not possible to route calls to A2DP sink (unless you do some great hacks, which does not conform to the BT spec). Ideally you should use HFP for audio calls.
HCI can transport both ACL and SCO. BT chips often have PCM interface to which SCO data can be routed but usually its not accessible unless you can access the PINs of the chip.
Also, please try to ask some precise questions (with log/code) so that we can really assist you. If you ask some generic questions, it is difficult to answer.

Is it possible to send/receive voice from PC to Android device over Bluetooth

I have a PC (where java program is running), Bluetooth dongle (which supports A2DP) and Android device (2.3.6, which also supports A2DP).
I want to:
Send real time voice data from PC's microphone to android device via bluetooth
Send real time voice data from Android device's microphone to PC via bluetooth
I found this question, where Dennis says that "Phones are typically only Source devices (Source of the stream that can stream to sink devices), Sinks are Headsets or Bluetooth speakers.". So it seems it is possible to implement case 2? Or not? And what about case 1, is it impossible to implement?
It is true that Android phone are uniquely A2DP source devices.
Sadly, your first case is impossible to realize if you decide to rely on the A2DP profile for streaming audio, because Android does not implement the required callbacks supposed to be handling BlueZ's advertisings when a remote device wants to stream audio to your phone.
The second use case is possible, given that you have a bluetooth enabled PC and some awesome apps that will decode and route the sound from the Bluetooth stack to the speakers. I managed once to reproduce this use case using PulseAudio and pulseaudio-module-bluetooth on Ubuntu 12.10.
Here is a working example showing how to manage the routing of the sound once a connected BT device begins to stream. Here is another one. They both take place on Linux and I never did this on Windows though.
For the sake of completeness, here is another SO answer written by me, giving details about how to implement A2DP sink capabilities on Android.
EDIT :
Nothing forbids you to implement your own protocol for audio streaming via Bluetooth on an Android device, this will work, but as it will not be a standard, it will never comply with the system built-in Bluetooth profiles (A2DP, HFP ...).

How to make an Android phone as bluetooth headset

I have 2 Android Phones, and I want to connect them together via bluetooth, and make one of them a bluetooth headset.
So, my question is how to program the second phone to change its role profile to "Bluetooth Headset" when establishing the connection ?
I've found this post but my question is a little bit different
Thank for any advice or idea :)
You cannot on Android. At least using the built-in Bluetooth A2DP profile.
Your phone will only act as a transmitter (source), not a receiver (sink).
Please look at these two answers I gave on why this is not possible :
Is it possible to send/receive voice from PC to Android device over Bluetooth
Receive audio via Bluetooth in Android
You can, on the other hand, develop two apps each acting as a client/server using your own protocol. The server could be streaming audio content to the client via Bluetooth for instance.
Another way to consider this, since using an Android device as an A2DP sink is not feasible on every phone, is building these two apps using your wifi connection. It could be much more rapid and the sound sound be of a much better quality.

Categories

Resources