在 C# 中将音频流式传输到蓝牙设备

Stream Audio to Bluetooth Device in C#

我正在尝试以 C# 代码将音频流式传输到蓝牙设备。我选择了 32feet.net 库来帮助解决这个问题。我能够很好地配对蓝牙扬声器,然后我使用下面的代码连接到设备。

    globalClient.BeginConnect(device.DeviceAddress, BluetoothService.SerialPort, new AsyncCallback(BluetoothConnectedAsyncHandler), device);

异步回调方法:

    private void BluetoothConnectedAsyncHandler(IAsyncResult result)
    {
        BluetoothDeviceInfo connectedDevice = (BluetoothDeviceInfo)result.AsyncState;

        globalClient.EndConnect(result);

        if (result.IsCompleted)
        {
            NetworkStream btStream = globalClient.GetStream();
        }
    }

一切正常,但是当我尝试将服务从 BluetoothService.SerialPort 设置为 BluetoothService.AudioSource 时,我在 "globalClient.EndConnect(result);" 行收到一个 SocketException 说 "A socket operation failed because the destination host was down" .见截图:

当使用 BluetoothService.SerialPort 设置时,我还尝试通过 NetworkStream 向扬声器发送数据,但它不播放任何内容 - 没有噪音或静电。

我的 运行 假设是 32feet.net 无法轻松完成此操作,我必须在代码中编写 a2dp 规范。我认为使用 32feet.net 库是为了告诉操作系统将扬声器用作输出设备,而不是将代码中的音频输出控制为支持的功能。

请帮忙!有人做过吗?

如果我通过 BluetoothService.SerialPort 连接向设备发送符合 a2dp 的流,它会工作吗?

A2DP 规格:https://www.bluetooth.org/docman/handlers/DownloadDoc.ashx?doc_id=8236

感谢您的帮助!

更新:

这在 32feet.net 库中是不可能的,您只能使用 32feet.net

中的 setService 方法调用将设备设置为与 Microsoft 音频服务通话

www.nudoq.org/#!/Packages/32feet.NET/InTheHand.Net.Personal/MicrosoftSdpService/M/SetService

此 MS 服务管理到设备的 A2DP 输出。在 C# 中使用此库无法直接将音频从代码输出到蓝牙设备。