如何以编程方式创建一个A2DP连接或我怎么能效仿Android手机是一个A2DP片? [英] How to create programmatically an A2DP connection or how can I emulate an Android phone to be an A2DP sink?

查看:869
本文介绍了如何以编程方式创建一个A2DP连接或我怎么能效仿Android手机是一个A2DP片?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个Android手机(三星Galaxy Tab和HTC Desire的)。两个2.2。 Galaxy Tab的应该是一个A2DP片和欲望的源泉。我的目标是路由欲望银河的声音。我只是说有可能建立一个RFCOMM连接的API中看到的。但我想建立一个A2DP连接。我的解决方案的需求是没有的手机应该扎根。

I have two android phones (Samsung Galaxy Tab and HTC Desire). Both 2.2. The Galaxy Tab should be an A2DP sink and the Desire the source. My aim is to route the sound of the Desire to the Galaxy. I just saw in the API that it is possible to establish a RFCOMM connection. But I want to establish an A2DP connection. My requirements to the solution is that none of the phones should be rooted.

我发现在C <一个源$ C ​​$ href="http://grep$c$c.com/file/repository.grep$c$c.com/java/ext/com.google.android/android/2.2_r1.1/android/bluetooth/BluetoothUuid.java?av=f">Bluetooth UUID 类。我试图打开一个A2DP连接用的UUID。

I found in the source code the Bluetooth UUID class. And I tried to open a A2DP Connection with the UUIDs.

这是服务器端的code:

This is the code of the server side:

private class AcceptThread extends Thread {
  public AcceptThread() {
       try {
       BluetoothServerSocket mmServerSocket = btAdapter.listenUsingRfcommWithServiceRecord("Audio Sink", UUID.fromString("0000110B-0000-1000-8000-00805F9B34FB")); // UUID of Audio sink
       mmServerSocket = btAdapter.listenUsingRfcommWithServiceRecord(
    "AVCRP Controller", UUID.fromString("0000110E-0000-1000-8000-00805F9B34FB")); // UUID of AVCRP Controller                

    } catch (IOException e) {
    }
}

   public void run() {
// Keep listening until exception occurs or a socket is returned
while (true) {
try {
         socket = mmServerSocket.accept();

} catch (IOException e) {
    break;
}
// If a connection was accepted
if (socket != null) {
    try {
    mmServerSocket.close();
} catch (IOException e) {
    e.printStackTrace();
    }

code中的客户端的:

Code of the client side:

Method m = device.getClass().getMethod("createRfcommSocket", new Class[] { int.class });
tmp = (BluetoothSocket) m.invoke(device, Integer.valueOf(1));

我可以配对两个设备并可以创建一个连接。如果我去的Galaxy Tab的欲望和长preSS的蓝牙设置,我有菜单选项。我能看到的媒体形象。然后,如果尝试检查接线盒与所选配置文件我得到以下日志连接的设备:

I could pair both devices and could create a connection. If I go to the bluetooth settings of the Desire and long press on the Galaxy Tab, I have the menu OPTIONS. I can see the media profile. Then if tried to check the connection box to connect the device with the selected profiles I get following log:

04-11 17:21:18.994: DEBUG/DTUN_HCID4(1233):         dtun_client_get_remote_services()
04-11 17:21:18.994: INFO/DTUN_HCID4(1233): dtun_client_get_remote_services: Get remote services on 
04-11 17:21:18.994: INFO/DTUN_CLNT(1233):     Client calling DTUN_METHOD_DM_GET_REMOTE_SERVICES (id 5)
04-11 17:21:18.994: INFO/(1220): DTUN_ReceiveCtrlMsg: [DTUN] Received message [BTLIF_DTUN_METHOD_CALL] 4354
04-11 17:21:18.994: INFO/(1220): handle_method_call: handle_method_call :: received DTUN_METHOD_DM_GET_REMOTE_SERVICES (id 5), len 6
04-11 17:21:18.994: ERROR/BTLD(1220): ****************search UUID = 1108***********
04-11 17:21:18.994: WARN/BTLD(1220): ccb timer ticks: 0
04-11 17:21:19.005: INFO//system/bin/btld(1219):         btapp_dm_GetRemoteServices()
04-11 17:21:19.005: INFO//system/bin/btld(1219): ##### USerial_Ioctl: BT_Wake, 0x8003 ####
04-11 17:21:19.125: WARN/BTLD(1220): process_service_search_attr_rsp
04-11 17:21:19.144: WARN/BTLD(1220): ccb timer ticks: 0
04-11 17:21:19.155: ERROR/BTLD(1220): ****************search UUID = 111e***********
04-11 17:21:19.155: WARN/BTLD(1220): ccb timer ticks: 0
04-11 17:21:19.287: WARN/BTLD(1220): process_service_search_attr_rsp
04-11 17:21:19.287: WARN/BTLD(1220): ccb timer ticks: 0
04-11 17:21:19.336: ERROR/BTLD(1220): ****************search UUID = 110b***********
04-11 17:21:19.336: WARN/BTLD(1220): ccb timer ticks: 0
04-11 17:21:19.474: WARN/BTLD(1220): process_service_search_attr_rsp
04-11 17:21:19.474: WARN/BTLD(1220): ccb timer ticks: 0
04-11 17:21:19.534: INFO/BTL-IFS(1220): send_ctrl_msg: [BTL_IFS CTRL] send BTLIF_DTUN_SIGNAL_EVT (CTRL) 14 pbytes (hdl 15)
04-11 17:21:19.534: INFO/DTUN_HCID4(1233): dtun_dm_sig_rmt_services: success=1, service=00040040
04-11 17:21:19.534: DEBUG/DTUN_HCID4(1233): Adding UUID 0000111E-0000-1000-8000-00805F9B34FB
04-11 17:21:19.534: DEBUG/DEVICE(1233): Just add the profiles for /org/bluez/1233/hci0/dev_xx_xx_xx_xx_xx_xx
04-11 17:21:19.534: INFO/DTUN_HCID4(1233): Adding uuid 0000111E-0000-1000-8000-00805F9B34FB
04-11 17:21:19.534: DEBUG/DTUN_HCID4(1233): Adding UUID 0000110B-0000-1000-8000-00805F9B34FB
04-11 17:21:19.534: DEBUG/DEVICE(1233): Just add the profiles for /org/bluez/1233/hci0/dev_xx_xx_xx_x_xx_xx
04-11 17:21:19.534: INFO/DTUN_HCID4(1233): Adding uuid 0000110B-0000-1000-8000-00805F9B34FB
04-11 17:21:19.534: INFO/DTUN_HCID4(1233): Calling sink_init
04-11 17:21:19.534: DEBUG/ADAPTER(1233): adapter_get_device(Xx:xx:xx:xx:xx:xx)
04-11 17:21:19.534: DEBUG/DEVICE(1233): btd_device_ref(0xfa10): ref=2
04-11 17:21:19.534: INFO/DTUN_HCID4(1233): sink_init
04-11 17:21:19.534: DEBUG/DTUN_HCID4(1233): Registered interface org.bluez.AudioSink on path /org/bluez/1233/hci0/dev_xx_xx_xx_xx_xx_xx
04-11 17:21:19.544: ERROR/BluetoothEventLoop.cpp(96): event_filter: Received signal org.bluez.Device:PropertyChanged from /org/bluez/1233/hci0/dev_xx_xx_xx_xx_xx_xx
04-11 17:21:19.544: DEBUG/BluetoothService(96): updateDeviceServiceChannelCache(xx:xx:xx:xx:xx:xx)
04-11 17:21:19.554: INFO/DEVICE(1233): pattern = 0000111e-0000-1000-8000-00805f9b34fb, id = 4
04-11 17:21:19.564: DEBUG/BluetoothService(96):     uuid(system): 0000111e-0000-1000-8000-00805f9b34fb 4382
04-11 17:21:19.574: VERBOSE/BluetoothEventRedirector(492): Received android.bleutooth.device.action.UUID
04-11 17:21:19.700: WARN/BTLD(1220): ccb timer ticks: 0
04-11 17:21:20.615: INFO//system/bin/btld(1219): ##### USerial_Ioctl: BT_Sleep, 0x8004 ####
04-11 17:21:24.634: DEBUG/dalvikvm(594): GC_EXPLICIT freed 46 objects / 2320 bytes in 50ms
04-11 17:21:24.675: INFO/System.out(1336): public android.bluetooth.BluetoothA2dp(android.content.Context)
04-11 17:21:24.684: DEBUG/BluetoothA2dpService(96): connectSink(xx:xx:xx:xx:xx:xx)
04-11 17:21:24.684: INFO/BluetoothA2dpService(96): checkSinkSuspendState() : state = 1 prevState = 0
04-11 17:21:24.684: INFO/BluetoothA2dpService(96): checkSinkSuspendState() : mTargetA2dpState = -1
04-11 17:21:24.684: INFO/BluetoothA2dpService(96): checkSinkSuspendState() : initialStart = false initialSuspend = false
04-11 17:21:24.694: VERBOSE/BluetoothEventRedirector(492): Received android.bluetooth.a2dp.action.SINK_STATE_CHANGED
04-11 17:21:24.694: DEBUG/CachedBluetoothDevice(492): onProfileStateChanged:[]
04-11 17:21:24.705: DEBUG/BluetoothA2dpService(96): A2DP state : device: BC:47:60:0F:4B:F3 State:0->1
04-11 17:21:24.705: INFO/DTUN_CLNT(1233):     Client calling DTUN_METHOD_AM_AV_OPEN (id 20)
04-11 17:21:24.705: INFO/(1220): DTUN_ReceiveCtrlMsg: [DTUN] Received message [BTLIF_DTUN_METHOD_CALL] 4354
04-11 17:21:24.705: INFO/(1220): handle_method_call: handle_method_call :: received DTUN_METHOD_AM_AV_OPEN (id 20), len 6
04-11 17:21:24.705: ERROR/BTLD(1220): reset flags
04-11 17:21:24.705: WARN/BTLD(1220): ccb timer ticks: 0
04-11 17:21:24.705: DEBUG/DTUN_HCID4(1233): stream creation in progress
04-11 17:21:24.714: INFO//system/bin/btld(1219): ##### USerial_Ioctl: BT_Wake, 0x8003 ####
04-11 17:21:24.958: WARN/BTLD(1220): process_service_search_attr_rsp
04-11 17:21:25.017: WARN/BTLD(1220): ccb timer ticks: 0
04-11 17:21:25.227: ERROR/BTLD(1220): bta_av_rc_create ACP handle exist for shdl:0
04-11 17:21:25.325: WARN/BTLD(1220): bta_dm_rm_cback:0, status:1
04-11 17:21:25.325: WARN/BTLD(1220): bta_dm_act no entry for connected service cbs
04-11 17:21:25.325: INFO/BTL-IFS(1220): send_ctrl_msg: [BTL_IFS CTRL] send BTLIF_DTUN_SIGNAL_EVT (CTRL) 44 pbytes (hdl 15)
04-11 17:21:25.325: WARN/BTLD(1220): btui_av_callback(BTA_AV_OPEN_EVT::FAILED (page-timeout or protocol)::status: 3
04-11 17:21:25.325: INFO/DTUN_HCID4(1233): pending
04-11 17:21:25.325: INFO/DTUN_HCID4(1233): orig_msg = e588
04-11 17:21:25.325: ERROR/BluetoothA2dpService.cpp(96): onConnectSinkResult: D-Bus error: org.bluez.Error.Failed (Stream connection failed)
04-11 17:21:25.325: INFO/BluetoothA2dpService(96): checkSinkSuspendState() : state = 0 prevState = 1
04-11 17:21:25.325: INFO/BluetoothA2dpService(96): checkSinkSuspendState() : mTargetA2dpState = -1
04-11 17:21:25.325: INFO/BluetoothA2dpService(96): checkSinkSuspendState() : initialStart = false initialSuspend = false
04-11 17:21:25.334: VERBOSE/BluetoothEventRedirector(492): Received android.bluetooth.a2dp.action.SINK_STATE_CHANGED
04-11 17:21:25.334: INFO/BluetoothEventRedirector(492): Failed to connect BT A2DP
04-11 17:21:25.334: DEBUG/CachedBluetoothDevice(492): onProfileStateChanged:[]
04-11 17:21:25.334: DEBUG/BluetoothA2dpService(96): A2DP state : device: BC:47:60:0F:4B:F3 State:1->0
04-11 17:21:25.925: INFO//system/bin/btld(1219): ##### USerial_Ioctl: BT_Sleep, 0x8004 ####
04-11 17:21:26.775: WARN/BTLD(1220): ccb timer ticks: 2147483648
04-11 17:21:26.785: INFO//system/bin/btld(1219): ##### USerial_Ioctl: BT_Wake, 0x8003 ####
04-11 17:21:27.725: INFO//system/bin/btld(1219): ##### USerial_Ioctl: BT_Sleep, 0x8004 ####

有谁知道我在做什么错了? 一般的问题是,它可以从一个电话连接两个Android手机通过蓝牙和数据流其他?你有什么其他办法?

Does anyone know what I am doing wrong? A general question is it possible to connect two Android phones via Bluetooth and stream from one phone to the other? Do you have any alternative approaches?

感谢

推荐答案

您不能这样做了 RFCOMM / SPP - 连接到 A2DP UUID 是不够的 - 配置文件连接/ profile文件级协议的程序需要进行实施 A2DP - 越飞越 A2DP 直接工作了 L2CAP协议(并且不需要 RFCOMM )。

You cannot do it over RFCOMM / SPP - Connecting to A2DP UUID is not enough - the Profile connection / profile level protocol procedures need to be done to implement A2DP - more over A2DP directly works over L2CAP protocol (and does not require RFCOMM).

您可能-不能2手机之间做手工也因为流中的一个设备需要支持A2DP片等其他A2DP源,手机通常只有源设备,可以传输到终端设备的数据流(来源),接收器是耳机蓝牙音箱

You may-not be able to do it manually between 2 phones also because to stream one device needs to be A2DP sink and other other A2DP source, Phones are typically only Source devices (Source of the stream that can stream to sink devices) , Sinks are Headsets or Bluetooth speakers.

这篇关于如何以编程方式创建一个A2DP连接或我怎么能效仿Android手机是一个A2DP片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆