Reputation: 3850
The scenario:
My friends and I are developing a product with a bluetooth reciever that connects to a speaker system. Currently we can pair with this unit and stream music over a bluetooth connection. I'd like to develop an app that I can use to control different settings on our unit while the music is streaming. My application needs to be able to do this no matter which app is streaming the music over bluetooth (native media player, spotify, pandora etc.). I'm thinking this potentially a permissions issue as opposed to a bandwidth issue...
I need to know:
Is it possible to send control data and an audio stream concurrently to the same bluetooth reciever? If so, could someone please point toward a good strategy that will help me accomplish this (eg what protocol to use for the control data)? If it is not possible, can someone recommend a better way to control the target device?
I wasn't able to find what I was looking for in the Android Developer docs.
Upvotes: 1
Views: 1308
Reputation: 61
Based on my knowledge from working with bluetooth, the best method would be to send the control packets in the same packet stream as the audio packets, appending a unique ID to allow the speaker the ability to recognize and act on the control packets.
Ideally, you would want a Connection Stream on the speaker built just for control. so that way your app just connects to that and sends the connection data, which the speaker then interprets.
Pseudo code for the speaker would look something like
connectionURL = "btspp://localhost: " + uuid + ";name=control";
bluetoothConnection.open(url);
while (true) {
// waits on this line until something tries to connect to it.
bluetoothConnection.acceptAndOpen();
/* Process control information */
}
As for pausing music from a third party app, the easiest way would be to have the App Request Audio Focus to pause and release it to resume. Alternatively, you could have a control packet sent that would cancel the bluetooth stream of audio, but that could become quite complicated to resume.
Upvotes: 1