Android audio output to bluetooth

Is it possible to direct all audio output, including music output, to a Bluetooth headset?

I am able to make and receive calls from my Samsung ACE S5830 phone using a Bluetooth device. However, when I play MP3 songs on my phone, the output does not play through the Bluetooth mono headset; it just directly plays from the phone’s speakers. Is there a way to direct all audio output to the Bluetooth mono headset?

8 Answers 8

I did some googling and stumbled across this post on androidforums.com which has some suggestions:

  1. There are several apps which appear to provide this functionality. BTmono is the only free one I found that isn’t limited to a certain length of time. It requires Android 2.2+. There are several other similar apps that you can also see at that link.
  2. This person posted a trick which looks like it works without the use of an additional app:
  1. I went to the phone and dialed ‘**’ (2 stars) which creates a ‘p’ for pause. Then press call. This enables the headset without actually placing a call.
  2. After this I started doggcatcher (or other audio / video player) and it played through the headset. Everything went through the headset after this point.
  3. In order to stop playback to my headset I just called my voicemail and hung up. At that point, audio was routed back to the speaker.

Generally, audio apps use the media channel, which will be played over Bluetooth if your Bluetooth device supports that A2DP profile.

Check the specs on your headset to see if it supports A2DP — if it does, please edit your question to include additional information on the music app you use and the make and model of your headset.

  1. You want to hear music on your bluetooth device
  2. Your bluetooth device pairs perfectly with your android phone.
  3. It works only with calls, media still plays on your device speakers.

BTMono is a great tool that suits your requirement. It will allow you to simply turn ON media streaming and you are good to go.

Remember that it is free and you need to restart the app after every phone call. This feature can be unlocked in the pro version which is just $1 😀

Источник

How to stream audio from one Android device to another Android device Via Bluetooth?

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 link

Читайте также:  Mystery mdd 6270nv блютуз

Thank you for that link @ashish. I am go through that. And will let you know what happens. Thanks again.

Does the audio need to be streamed via Bluetooth? What about using WiFi-Direct? This would actually give you more flexibility and features.

5 Answers 5

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.

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.

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 🙂

// 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

assume you already got the BluetoothDevice

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

Источник

Routing audio to Bluetooth Headset (non-A2DP) on Android

I have a non-A2DP single ear BT headset (Plantronics 510) and would like to use it with my Android HTC Magic to listen to low quality audio like podcasts/audio books. After much googling I found that only phone call audio can be routed to the non-A2DP BT headsets. (I would like to know if you have found a ready solution to route all kinds of audio to non-A2DP BT headsets) So I figured, somehow programmatically I can channel the audio to the stream that carries phone call audio. This way I will fool the phone to carry my mp3 audio to my BT headset. I wrote following simple code.

import android.content.*; import android.app.Activity; import android.os.Bundle; import android.media.*; import java.io.*; import android.util.Log; public class BTAudioActivity extends Activity < private static final String TAG = "BTAudioActivity"; private MediaPlayer mPlayer = null; private AudioManager amanager = null; @Override public void onCreate(Bundle savedInstanceState) < super.onCreate(savedInstanceState); setContentView(R.layout.main); amanager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); amanager.setBluetoothScoOn(true); amanager.setMode(AudioManager.MODE_IN_CALL); mPlayer = new MediaPlayer(); try < mPlayer.setDataSource(new FileInputStream( "/sdcard/sample.mp3").getFD()); mPlayer.setAudioStreamType(AudioManager.STREAM_VOICE_CALL); mPlayer.prepare(); mPlayer.start(); >catch(Exception e) < Log.e(TAG, e.toString()); >> @Override public void onDestroy() < mPlayer.stop(); amanager.setMode(AudioManager.MODE_NORMAL); amanager.setBluetoothScoOn(false); super.onDestroy(); >> 
  • Using MediaPlayer’s setAudioStreamType(STREAM_VOICE_CALL)
  • using AudioManager’s setBluetoothScoOn(true)
  • using AudioManager’s setMode(MODE_IN_CALL)
Читайте также:  Где мой блютуз на ноутбуке

But none of the above worked. If I remove the AudioManager calls in the above code, the audio plays from speaker and if I replace them as shown above then the audio stops coming from speakers, but it doesn’t come through the BT headset. So this might be a partial success.

I have checked that the BT headset works alright with phone calls.

There must be a reason for Android not supporting this. But I can’t let go of the feeling that it is not possible to programmatically reroute the audio. Any ideas?

P.S. above code needs following permission

You may not need to write any code yourself. Simply install a free app which is designed to do what you want. See the Android.SE question: «Is it possible to direct all audio output, including music output, to a Bluetooth headset?» I tried a few different apps. In the end, «Mono Bluetooth Router» was the only one which worked for me.

5 Answers 5

This thread may be long dead but for those who might be trying the same thing, some notes from the AudioManager docs may be useful. It looks like the missing element is the startBluetoothSco() command but there are restrictions on the use of this channel. From the Android Dev site here:

public void startBluetoothSco () Since: API Level 8 Start bluetooth SCO audio connection.

Requires Permission: MODIFY_AUDIO_SETTINGS.

This method can be used by applications wanting to send and received audio to/from a bluetooth SCO headset while the phone is not in call.

As the SCO connection establishment can take several seconds, applications should not rely on the connection to be available when the method returns but instead register to receive the intent ACTION_SCO_AUDIO_STATE_CHANGED and wait for the state to be SCO_AUDIO_STATE_CONNECTED.

As the connection is not guaranteed to succeed, applications must wait for this intent with a timeout.

When finished with the SCO connection or if the establishment times out, the application must call stopBluetoothSco() to clear the request and turn down the bluetooth connection.

Even if a SCO connection is established, the following restrictions apply on audio output streams so that they can be routed to SCO headset: — the stream type must be STREAM_VOICE_CALL — the format must be mono — the sampling must be 16kHz or 8kHz

The following restrictions apply on input streams: — the format must be mono — the sampling must be 8kHz

Note that the phone application always has the priority on the usage of the SCO connection for telephony. If this method is called while the phone is in call it will be ignored. Similarly, if a call is received or sent while an application is using the SCO connection, the connection will be lost for the application and NOT returned automatically when the call ends.

Читайте также:  Chevrolet cruze 2012 блютуз

See Also stopBluetoothSco() ACTION_SCO_AUDIO_STATE_CHANGED

Note that I have not tested this, I’m just passing along a lead I found in researching a similar project. I think Jayesh was close to the solution and the restrictions above may have been what was keeping it from working.

Источник

Bluetooth audio streaming between android devices

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.

I did not understand what you need to know: sending audio from one Android to another, or sending audio from a standalone Bluetooth microphone to an Android?

Hello Sir, I need your help to steaming audio from one device to another device. Can you please give me any example code for this ? I have asked question : stackoverflow.com/questions/16789394/…

1 Answer 1

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.

Источник

Оцените статью
Adblock
detector