Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.

Revision as of 12:19, 2 February 2014 by croozeus (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

How to detect the audio path (headset connection) on Windows Phone

From Wiki
Jump to: navigation, search
Featured Article
02 Feb

This article explains how to detect if a headphone (or other audio endpoint) is plugged into a WP8 device using the VOIP AudioRoutingManager API.

Warning.pngWarning: This implementation doesn't work on GDR1 devices.

Note.pngNote: The article applies only to Windows Phone 8 devices.

WP Metro Icon Multimedia.png
SignpostIcon XAML 40.png
WP Metro Icon WP8.png
Article Metadata
Code ExampleTested with
SDK: Windows Phone 8.0 SDK
Devices(s): Nokia Lumia 820
Windows Phone 8
Created: marcodalpino (15 Sep 2013)
Updated: vinayppatil (28 Jan 2014)
Last edited: croozeus (02 Feb 2014)



There is no obvious API for detecting when the headphone jack is plugged or unplugged from the device, or for determining if any other type of headset is present.

This article introduces the Windows Phone 8 VOIP API's AudioRoutingManager class. While this class is provided mainly to route the audio to VOIP communications endpoints other than the phone's speaker, it also delivers AudioEndPointChanged events which can be used to determine the current audio endpoint device, and to be notified when this changes.

The article shows how to register to the events and determine whether the audio endpoint is a wired headphone or some other device.


This section shows how to query for the current audio endpoint and also how to register for notifications when the endpoint changes.

Query for the current AudioRoutingEndpoint using:

AudioRoutingEndpoint current = AudioRoutingManager.GetDefault().GetAudioEndpoint();

To get notified when the endpoint status changes, we first need to register a handler for the event:

AudioRoutingManager.GetDefault().AudioEndpointChanged += AudioEndpointChanged_Handler;

The different endpoints can be determined from the AudioRoutingEndpoint enum:

Member Description
Default The default audio endpoint, that is, the speakerphone
Earpiece An earpiece
Speakerphone The speakerphone
Bluetooth A Bluetooth device
WiredHeadset A wired headset
WiredHeadsetSpeakerOnly A wired headset for output only; the input is received from the default microphone
BluetoothWithNoiseAndEchoCancellation A Bluetooth device with noise and echo cancellation

Using the above enum values we can appropriately handle each case.

public void AudioEndpointChanged_Handler(AudioRoutingManager sender, object args)
var AudioEndPoint = sender.GetAudioEndpoint();
switch (AudioEndPoint)
case AudioRoutingEndpoint.Default:
//default audio devide
case AudioRoutingEndpoint.Earpiece:
case AudioRoutingEndpoint.Speakerphone:
case AudioRoutingEndpoint.Bluetooth:
case AudioRoutingEndpoint.WiredHeadset:
case AudioRoutingEndpoint.WiredHeadsetSpeakerOnly:
case AudioRoutingEndpoint.BluetoothWithNoiseAndEchoCancellation:
throw new ArgumentOutOfRangeException();

Source Code

Attached source file contains a AudioPathResolver.cs class with a Bindable property AudioPath. Also notice how AddNotificationHandler() and RemoveNotificationHandler() is called on HomePage's Load and UnLoad.


We can register for AudioEndPointChanged event on AudioRoutingManager and get notified whenever audio device changes.

This page was last modified on 2 February 2014, at 12:19.
171 page views in the last 30 days.