B4J Question Send music via Bluetooth a2dp

alizeti

Member
Licensed User
This is what I would like to do. Don't know if possible.

I would like to use the PC to scan available bluetooth speaker. Once detect and scan to it, I want to send music to the bluetooth device connected.

All this using the PC.
What do you guys suggest me.

Thanks
 

MathiasM

Active Member
Licensed User
B4J uses Bluecove I think, which doesn't support A2DP profiles. But does support RFCOMM protocol, so in theory it should be possible to send Headset Profile commands.
Here is some info on the Headset Profile: https://www.amd.e-technik.uni-rostock.de/ma/gol/lectures/wirlec/bluetooth_info/k6_hp.html
Altough the aim in sound quality of the Headset profile is lower than A2DP.

However, I have no idea how you could access the RFCOMM profile via B4J.
It's possible to use RFCOMM via the jSerial library, as you can map Bluetooth ports as serial ports, as @Erel states here in this post: https://www.b4x.com/android/forum/threads/jserial-library.34762/

So I think you can make a connection via the jBluetooth library, and then use that connected bluetooth COM port to send AT commands and transmit sound. This won't be easy though, as this is virgin ground for B4J, I think.

Good luck researching. (Mind the fact that I use 'I think', 'In theory' in my sentences, I'm not an expert by any means.)
 
Last edited:
Upvote 0

techknight

Well-Known Member
Licensed User
Longtime User
B4J uses Bluecove I think, which doesn't support A2DP profiles. But does support RFCOMM protocol, so in theory it should be possible to send Headset Profile commands.
Here is some info on the Headset Profile: https://www.amd.e-technik.uni-rostock.de/ma/gol/lectures/wirlec/bluetooth_info/k6_hp.html
Altough the aim in sound quality of the Headset profile is lower than A2DP.

However, I have no idea how you could access the RFCOMM profile via B4J.
It's possible to use RFCOMM via the jSerial library, as you can map Bluetooth ports as serial ports, as @Erel states here in this post: https://www.b4x.com/android/forum/threads/jserial-library.34762/

So I think you can make a connection via the jBluetooth library, and then use that connected bluetooth COM port to send AT commands and transmit sound. This won't be easy though, as this is virgin ground for B4J, I think.

Good luck researching. (Mind the fact that I use 'I think', 'In theory' in my sentences, I'm not an expert by any means.)

There are a few holes in that theory. Thanks for the thought though! but RFCOMM is for SPP profiles, not HFP or A2DP or any of those other type of protocols.

So Yes, your right, you can use RFCOMM and pair up Bluetooth adapters to your program, and use them as serial ports. But you can ONLY use them as serial ports. You cant do A2DP Audio or anything else. You need a wrapper or a native DLL that can drill down to the native Bluetooth API to do anything else.

Also as a serial port, What are you going to send AT commands to? Thats the other problem. Send AT commands to what... and AT commands =/= audio. Again audio has its own transport layer and bluetooth stack/protocol known as A2DP.

I know with VB .Net and C#, you can use windows DLLs or other Bluetooth DLLs to get access to the entire profile set. But with Java, no idea.

However as a workaround, They make bluetooth adapters than can simulcast bluetooth stacks. So you can run A2DP and SPP together. So your App can take over the SPP side, but the A2DP Audio side would purely be dealt with by the OS, like Windows. so you would treat it as any other native audio source, and just use MediaPlayer. It will play out of the A2DP Audio as long as its set as the default playback source.

I have done something very similar with an Android head unit. I had a Bluegiga W32i that was programmed to run as A2DP and SPP together.

I paired the A2DP and SPP side to Android, and Android itself takes over the A2DP setup as normal for an audio device. Thats how my audio was sent to the amplifier that was in the car. However, I also have the SPP side so I can send commands through the same bluetooth link over the UART thats in the W32, so I can control things like volume, Equalizer, Bass/Treble boost, subsonic filters, etc, basically to control the processing circuits that I shoved in the amplifier's design.

its been a few years since I have done this so I cant remember the intricate details.

https://www.silabs.com/documents/login/data-sheets/WT32i-DataSheet.pdf
 
Last edited:
Upvote 0

MathiasM

Active Member
Licensed User
There are a few holes in that theory. Thanks for the thought though! but RFCOMM is for SPP profiles, not HFP or A2DP or any of those other type of protocols.

So Yes, your right, you can use RFCOMM and pair up Bluetooth adapters to your program, and use them as serial ports. But you can ONLY use them as serial ports. You cant do A2DP Audio or anything else. You need a wrapper or a native DLL that can drill down to the native Bluetooth API to do anything else.

Also as a serial port, What are you going to send AT commands to? Thats the other problem. Send AT commands to what... and AT commands =/= audio. Again audio has its own transport layer and bluetooth stack/protocol known as A2DP.

You're right, but I clearly stated HSP as the only alternative for audio, because audio can be transmitted over RFCOMM via the HSP protocol. I know this is not the same as A2DP, but it's audio none the less. And it could be a solution if 'great' audio quality isn't a necessity for the project of @alizeti

Correct me if I'm wrong, that's how I understand it from my bluetooth research (which is not a whole lot, I'm aware of that)
 
Upvote 0

techknight

Well-Known Member
Licensed User
Longtime User
I guess it depends on what you need. I found HFP to be of horrible quality, and I dont even know if HFP is even supported through RFCOMM anymore. Mainly today, 90% of its use is for SPP.
 
Upvote 0
Top