How to read Bluetooth Headset buttons
with Ozeki VoIP SIP SDK using C#?
This example demonstrates how to fetch events generated by pressing bluetooth buttons. You can connect these events to your C# application and catch them by an active window. If a window pops up it becomes active. It is a great way to accept or reject incoming calls.
Do not forget that your bluetooth headsets must be paired with the machine that runs Ozeki VoIP SIP SDK. You will know that it is paired from the constantly glowing blue LED. If the LED is flashing your device is turned on, although it is not paired. Use a bluetooth adapter to pair it.
Remember that you need to INVITE SIP requests to answer the call, which you can fully understand if you study How to register to a SIP PBX chapter and the How to accept incoming call chapter first. Keep in mind that you need to have Ozeki VoIP SIP SDK installed, and a reference to ozeki.dll should be added to your C# project. Try out this example with Visual Studio.
A short reminder how to accept calls
Softphones created by the Ozeki VoIP SIP SDK can get notifications of incoming calls by
subscribing to the Incmoning Call event of the softphone's object.
You can accept the call if the event occurs with the Answer() method which you can
find in the call object. Answer() changes the call's state to 'InCall'.
Connect your Bluetooth Headset to Windows
Our example works on Microsoft Windows, but keep in mind to plug in an USB Bluetooth adapter before connecting your Bluetooth Headset. Turn on your headset and connect it to the operating system (Figure 2).
Logging bluetooth buttons
Find a great example in Ozeki VoIP SIP SDK that logs any bluetooth keypress (Figure 3).
- BluetoothHeadSetButtonHandling_WF (Workflow Foundation project)
- BluetoothHeadSetButtonHandling_WPF (Windows Presentation Foundation)
You can find them in the following directory:
How does the C# example work
Look at 'MainForm.cs' from BluetoothHeadSetButtonHandling_WF (Figure 4)
This code renders an event to the button (button1.Click += Button1_Click;) By clicking it, you can open the 'Key Event Window' as seen on Figure 3. An '_eventWindow_OnMediaKeyPressed' event will be rendered to the window as well. If called, this event will generate an AddToLogBox(e) method, where 'e' contains the event args to be logged on 'MainWindow' (Figure 3, above).
using System; using System.Windows.Forms; using Ozeki.Media; namespace BluetoothHeadSetButtonHandling_WF { public partial class MainForm : Form { public MainForm() // is 'MainWindow' on Figure 3 { InitializeComponent(); button1.Click += Button1_Click; } private BluetoothHeadsetButtonListener_WF _eventWindow; private void Button1_Click(object sender, EventArgs e) { if(_eventWindow == null) { _eventWindow = new BluetoothHeadsetButtonListener_WF(this); _eventWindow.OnMediaKeyPressed += _eventWindow_OnMediaKeyPressed; _eventWindow.FormClosed += _eventWindow_FormClosed; } _eventWindow.Show(); _eventWindow.Activate(); _eventWindow.WindowState = FormWindowState.Normal; } private void _eventWindow_FormClosed(object sender, FormClosedEventArgs e) { _eventWindow.OnMediaKeyPressed -= _eventWindow_OnMediaKeyPressed; _eventWindow.FormClosed -= _eventWindow_FormClosed; } private void _eventWindow_OnMediaKeyPressed (object sender, Ozeki.Common.OzMediaButtonEventArgs e) { var action = new Action(() => AddToLogBox(e)); BeginInvoke(action); } private void AddToLogBox(Ozeki.Common.OzMediaButtonEventArgs e) { logBox.Items.Add(e); logBox.SelectedIndex = logBox.Items.Count - 1; } } }
More information
- How to build a softphone voip sip client
- Register to SIP PBX
- Voip softphone development
- How to encrypt voip sip calls with sip encryption
- How to encrypt voip sip calls with rtp encryption
- How to ring a sip extension csharp example for sip invite
- How to make a sip voice call using csharp
- Voip multiple phone lines
- How to send stream of voice data into call using csharp microphone
- How to receive voice from SIP voice call using csharp speaker
- How to make conference voice call using voip sip
- How to play an mp3 file into a voice call using csharp
- How to convert text to speech and play that into a call using csharp
- How to use Microsoft Speech Platform 11 for TTS and STT
- How to record voip sip voice call
- How to accept incoming call using csharp
- How to reject incoming call using csharp
- How to implement auto answer using csharp
- How to recognize incoming voice using speech to text conversion
- Voip forward call
- Voip blind transfer
- Voip attended transfer
- Voip do not disturb
- Voip call hold
- SIP Message Waiting Indication
- Voip DTMF signaling
- How to work with sip and sdp in voip sip calls
- How to work with rtp in voip sip calls
- How to make voip video calls in csharp
- Voip video codec
- Shows how to use SpeechToText Google API
- How to convert Text to Speech using C# and Google