26
votes

Is it possible to stream audio over bluetooth? During my research I found that is it only possible using A2DP(Advanced Audio Distribution Profile). And does every android device support A2DP? If not, is it possible to stream audio between two android devices using bluetooth? Please help me understand this.

I've looked through the following links:

5
1. Almost every device supports A2DP, A2DP and HFP(Handsfree) profile are the basic profiles which phone needs. 2. Android 4.2.1 had audio streaming issues over bluetooth, it was a choppy audio which got fixed as per google in latest release. 3. Most of the people earlier had tried on bluez (open source bluetooth)stack but from JB onwards ,bluez is replaced by broadcomm stack. You need to implement audio sink profile in the phone. Audio streaming between 2 devices can be possible using Alljoyn, check linkashish
Thank you for that link @ashish. I am go through that. And will let you know what happens. Thanks again.Hardik Joshi
Does the audio need to be streamed via Bluetooth? What about using WiFi-Direct? This would actually give you more flexibility and features.BigMacAttack
@BigMacAttack thank you for reply. But I need streamed via Bluetooth.Hardik Joshi
@Prince: How about your progression? Does it work?John

5 Answers

11
votes

Is it possible to stream audio over Bluetooth?

Below sort of thread says its possibility that streaming audio over Bluetooth is possible between devices but there was question mark on its success rates till Google official announced that We have fixed the a2dp streaming stutter problem on N7. The next release should have the fix. Sorry about the problem.

Fix for poor A2DP quality on 4.2.2

Bluetooth sound quality suffer after upgrade to 4.2 with Galaxy Nexus

Android 4.3 Bluetooth Audio Quality Fix for Nexus 7 Flo

And does every android device support A2DP?

Support compatibility is mention on Android developers site that its added from API Level-11 with appropriate features. But I came across XDA tread where OP mention problem in Android 2.1,means its also support in previous api levels but OP facing issues.

Hope it make sense to understand and I would like to recommend to refer XDA forum to get more information about A2DP compatibility and its sucess.

1
votes

I my opinion, if A2DP doesn't work properly, we'd better move to lower layer, and we can create a basic stream which can be used for sending any form of date. I succeed in sending byte stream via Bluetooth between J2ME devices.

If install an app in both devices is acceptable, I've sample codes to create a Bluetooth server and a client to communicate with each other via socket, once the socket is established, you can send you audio stream :)

here are some core codes:

1) server device:

// you can generate your own UUID and use it as an port to eatablish a socket
private static final UUID MY_UUID = UUID.fromString("20687DAD-B023-F19E-2F60-A135554CC3FD")

BluetoothServerSocket serverSocket = mBluetoothAdapter.listenUsingRfcommWithServiceRecord(NAME_INSECURE, MY_UUID);

now you have the serverSocket, just use it as an ordinary ServerSocket:

BluetoothSocket socket = serverSocket.accept();

and then you can get InputStream and OutputStream from this BluetoothSocket and send audio stream just like HttpConnection

2) client device:

assume you already got the BluetoothDevice

// you should implement the method getBlutoothDevice
BluetoothDevice device = getBluetoothDevice();
BluetoothSocket socket = device.createRfcommSocketToServiceRecord(MY_UUID_SECURE);
1
votes

You can also stream audio over a basic SCO connection which is not dependent on any profile. However, be aware that A2DP is a profile that was developed specifically for streaming music. So any implementation that you make yourself will suffer in quality compared to A2DP.

Unless you are streaming music to a device which does not support A2DP, I would certainly use A2DP. Really your only other option is to use a SCO link.

-1
votes

Try using following code snippet:

    public class AudioStream extends Activity {

 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  String url = "http://www.example.mp3";
  MediaPlayer mp = new MediaPlayer();
  try {
   mp.setDataSource(url);
   mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
   mp.prepare();
   mp.start();
  } catch (Exception e) {
   Log.i("Exception", "Exception in streaming = " + e);
  }
 }
}
-1
votes

It's really hard to do that. But I did a lot of research and got a way. Has several delay, connection and root problems, but apparently works. For this you will need to have the "AirAudio" application installed on the server and the "AllConnect" receiver. Then you open AirAudio on the home screen and then open AllConnect, press on your device, then on sources and choose the server, then choose the streaming mp3. The problem is that the delay is very large and another defect is that to transmit only the sound of the system of the android server you should have root on the phone ... I also tried the receiver of the streaming being the VLC, was less delayed but still So it's uncomfortable.