Send a audio tone to my Bluetooth head set.

Topics: Bluetooth - Microsoft
Nov 14, 2012 at 7:39 PM

Hello 

I want a simple program which creates a connection to a Bluetooth headset send a tone and closes.  (From my PC (windows 7/8) to a Bluetooth Headset)

Now i tried several way to do this. Many posts mention that use SetServiceState . So i wrote the following program. Nothing seems to happen. I mean what i was hoping from this program that the OS automatically connects to the headset, instead of me connecting to it manually through control panel. But no effect. 

 

private static void connectBluetooth()
        {
            string MacAdresse = "0018914F0765";
            
            Guid service = BluetoothService.Headset;

            InTheHand.Net.Bluetooth.BluetoothRadio radio = InTheHand.Net.Bluetooth.BluetoothRadio.PrimaryRadio;

            InTheHand.Net.Sockets.BluetoothClient client = new BluetoothClient();
            BluetoothDeviceInfo[] list = client.DiscoverDevicesInRange();
            for (int i = 0; i < list.Length; i++)
            {

                if (MacAdresse == list[i].DeviceAddress.ToString())
                {
                    list[i].SetServiceState(BluetoothService.Headset, true);
                }
            }

        } 

 

Some one suggested to use client.connect so i wrote this function. Surprisingly the connection happens. But not with the underlying OS but this connection is between my application and the Bluetooth headset. I am fine by that but now how do i send audio data to the device ? Will client.GetStream(); work some how ? I think it should be pretty easy to do this, and i am definitely missing something.  

 

private static void pairHandsfree()
        {
            string MacAdresse = "0018914F0765";
            string pin = "0000";
            Guid service = BluetoothService.Headset;

            InTheHand.Net.Bluetooth.BluetoothRadio radio = InTheHand.Net.Bluetooth.BluetoothRadio.PrimaryRadio;


            InTheHand.Net.Sockets.BluetoothClient client = new BluetoothClient();
            BluetoothDeviceInfo[] list = client.DiscoverDevicesInRange();
            for (int i = 0; i < list.Length; i++)
            {
                //MessageBox.Show(list[i].DeviceName.ToString());

                if (MacAdresse == list[i].DeviceAddress.ToString())
                {
                    InTheHand.Net.BluetoothEndPoint endpoint_dev = new InTheHand.Net.BluetoothEndPoint(list[i].DeviceAddress, Guid.NewGuid());
                    endpoint_dev.Service = BluetoothService.Headset;
                    client.SetPin("0000");
                    client.Connect(endpoint_dev);
                   
                }
 
            }

           
        } 

 

Is it possible to do what i am wanting to do using 32feet ? 

Nov 14, 2012 at 11:52 PM

Can some one give some direction here ?

Developer
Nov 16, 2012 at 9:31 AM

What version of Windows are you using? There's support in-box for Windows 8 to use a Bluetooth handsfree and Windows 7 can normally download an update to make it work. I've used a headset on both platforms.

There's even a MSFT sample from Windows 8: http://code.msdn.microsoft.com/windowsapps/Call-Control-b52ad696/view/Discussions

 

It is a very difficult task to get Bluetooth audio working when Bluetooth code. Audio is transferred over SCO for which there isn't a easy API.