Android设备之间的蓝牙音频流

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20159457/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 02:23:23  来源:igfitidea点击:

Bluetooth audio streaming between android devices

androidbluetoothstreamingaudio-streaminga2dp

提问by Nidhin Joseph

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.

我对同一主题进行了研究,发现 android 设备是 a2dp 源,并且音频只能从 a2dp 源流式传输到 a2dp 接收器。A2dp sink 可以是蓝牙耳机或蓝牙音箱。

But my question is then how the android app named"Bluetooth Music Player" works?

但我的问题是名为蓝牙音乐播放器的 android 应用程序如何工作的

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?

它允许从一部手机流式传输到另一部手机。因此,在这种情况下,收听移动设备必须充当接收器。这怎么可能?他们是否使用其他配置文件而不是 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.

请帮忙。

采纳答案by Schlangi

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.

在不了解所提到的蓝牙音乐播放器的详细信息的情况下,它似乎使用简单的蓝牙数据连接,否则您将不需要在播放/发送设备上安装客户端。

要将音频从麦克风流式传输到另一台设备,您可以将其录制在发送设备上并将其发送到接收设备。您将需要为此目的实施协议。
或者
您可以实现替代的 A2DP 接收器服务。这就是接收器是什么:具有蓝牙协议栈和 A2DP 接收器实现的设备。

编辑:
对于您在评论中详述的情况,发送设备应保持原样,无需安装任何应用程序。这隐含地意味着您的解决方案必须利用该 Android 设备的开箱即用蓝牙功能。
因此,您在这里可以使用的仅限于 Android 通常支持的配置文件,即 HSP、HFP 和 A2DP。由于您显然想要流式传输音乐,因此 A2DP 将是您的选择。
在应该接收音频流并进行播放的设备上,您必须实现提供 A2DP 接收器的服务,作为自实现的 BluetoothService 在 RFCOMM 上打开 BluetoothServerSocket,如Android 文档中所述

您将不得不花费大量精力来实现这一点,我不确定您是否需要为此获得许可证。