How to make the Bluetooth speakers output sound faster after connected by programming?

yuan wong 1 Reputation point
2020-05-29T07:12:23.743+00:00

I have tried three ways to connect Bluetooth on WPF.

using Windows.Devices.Bluetooth;  
async void ConnectBTUWP()  
{  
  btdevice = await BluetoothDevice.FromIdAsync(BTId);  
  rfcommResult = await btdevice.GetRfcommServicesAsync();  
  rfcomm = rfcommResult.Services[1];  
  
    if (btdevice.ConnectionStatus != BluetoothConnectionStatus.Connected)  
      {  
        // Create a socket and connect to the target  
        var _socket = new StreamSocket();  
        await _socket.ConnectAsync(  
        rfcomm.ConnectionHostName,  
        rfcomm.ConnectionServiceName,  
        SocketProtectionLevel.BluetoothEncryptionAllowNullAuthentication);  
      }  
  
}  

------------------------------------------------------------------------

using InTheHand.Net;  
using InTheHand.Net.Sockets;  
using InTheHand.Net.Bluetooth;  
using System.Net.Sockets;  
  
public void ConnectBT(string MACAddr)  
{  
  var device = new BluetoothDeviceInfo(BluetoothAddress.Parse(MACAddr));  
  var remoteEP = new BluetoothEndPoint(device.DeviceAddress, BluetoothService.GenericAudio);  
  var socket = new Socket((AddressFamily)32, SocketType.Stream, ProtocolType.Ggp);  
  try  
  {  
     if (device != null)  
     {  
        socket.BeginConnect(remoteEP, null, null);  
     }  
  }  
  catch (Exception x)  
  {  
     Console.WriteLine("!ERROR! " + x);  
  }  
}  

------------------------------------------------------------------------

using InTheHand.Net;  
using InTheHand.Net.Sockets;  
using InTheHand.Net.Bluetooth;  
  
public void ConnectBT(string MACAddr)  
{  
  bl = new BluetoothClient();  
  var device = new BluetoothDeviceInfo(BluetoothAddress.Parse(MACAddr));  
  var remoteEP = new BluetoothEndPoint(device.DeviceAddress, BluetoothService.GenericAudio);  
    
  try  
  {  
     if (device != null)  
     {  
      device.SetServiceState(BluetoothService.AudioSink, true);  
      device.SetServiceState(BluetoothService.AVRemoteControl, true);  
      device.SetServiceState(BluetoothService.Handsfree, true);  
      device.SetServiceState(BluetoothService.GenericAudio, true);  
      bl.BeginConnect(device.DeviceAddress, BluetoothService.GenericAudio, new AsyncCallback(BluetoothConnectedAsyncHandler), device);  
     }  
  }  
  catch (Exception x)  
  {  
     Console.WriteLine("!ERROR! " + x);  
  }  
}  

These are immediately connected to the Bluetooth speaker, ↓

8854-%E6%9C%AA%E5%91%BD%E5%90%8D.png

but no sound until "music" shown up. ↓ It takes 5 seconds.

8834-%E6%9C%AA%E5%91%BD%E5%90%8D.png

This problem can't see when I click the "connect" button,↓

8863-5.jpg

Bluetooth speaker connects as "Connected Voice, music" immediately.↓

8871-6.png

How to play sound faster like normal connect way when bt device connected by programming?
Thanks!

Not Monitored
Not Monitored
Tag not monitored by Microsoft.
35,959 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Alexander Maslov 6 Reputation points
    2021-06-04T19:53:36.45+00:00

    Hi. Did you find solution?

    0 comments No comments