1

For my Windows Phone 8.1 RT app I need to detect whether headphones are plugged in.

I found this questions which answers this issue for Windows Phone 8.0 and Windows Phone 8.1 Silverlight apps: Windows Phone - Audio Endpoint Device

It tried this code in the code-behind of my main view (actually copied from http://developer.nokia.com/community/wiki/How_to_detect_the_audio_path_(headset_connection)_on_Windows_Phone):

   AudioRoutingEndpoint currentAudioRoutingEndpoint = AudioRoutingManager.GetDefault().GetAudioEndpoint();
   AudioRoutingManager.GetDefault().AudioEndpointChanged += AudioEndpointChanged_Handler;

and the handler:

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

If I run this code I get this exception: System.UnauthorizedAccessException was unhandled by user code HResult=-2147024891 Message=Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

I guess this is because the needed capabilities (ID_CAP_VOIP and ID_CAP_AUDIOROUTING) are missing. Now my problem is that in my Windows Phone 8.1 RT app there is only a package.appxmanifest and no WMAppManifest.xml and it seems I can't define these capabilities anymore.

Please note that I really have no WMAppManifest.xml in my project as it would be in a Windows Phone 8.1 Silverlight project (there are in fact both available).

  • Is there a way to add these capabilities for my WP 8.1 RT app?
  • Or is there another way to detect headphones in Windows Phone 8.1 RT I just didn't found?

I would really appreciate any help!

EDIT: changed Windows Phone 8.1 xaml to Windows Phone 8.1 RT

Community
  • 1
  • 1
Markus
  • 490
  • 6
  • 13
  • 1
    What project type are you using? 8.1 WinRT or 8.1 Silverlight? "Windows Phone 8.1 Xaml app" is not helping here ;) – sibbl Nov 28 '14 at 11:51
  • Windows Phone 8.1 WinRT. I were not sure about the correct naming...thanks. – Markus Nov 28 '14 at 13:16

2 Answers2

2

So two things:

  1. This feature is usable only during during a VOIP call, and only in the background task for the VOIP call - see the comments on this answer.
  2. These VOIP features are only available to Windows Phone 8.1 Silverlight apps, and again, only in VOIP background tasks. So no luck for WinRT 8.1 or Universal apps. The MSDN documentation is here (A list of other features not available in Phone 8.1 WinRT here)

So.. you probably can't do what you want to do on Windows Phone (unless you're building a VOIP app).

What feature are you trying to implement with this? Maybe there is an alternative.

Community
  • 1
  • 1
rikkit
  • 1,127
  • 3
  • 18
  • 35
  • I just want to detect whether there are some headphones plugged in or not. – Markus Nov 28 '14 at 15:04
  • You can't. Can you say why you want to do this, what you would do with this information if it were available, so we can suggest alternatives? – rikkit Nov 28 '14 at 15:48
  • We are developing a special app for musicians which uses the input from the microphone and computes an audio feedback. Can't get into details her but for computing the output we need to know whether it is played on the headphones or the phone's speakers. – Markus Nov 28 '14 at 16:40
  • I think you will have to settle with an on screen toggle so the user can say which mode they are in. – rikkit Dec 01 '14 at 10:41
1

in WP8.1 Runtime you can create a xml file WindowsPhoneReserveAppInfo.xml with below code:

<?xml version="1.0" encoding="utf-8" ?>
<WindowsPhoneReservedAppInfo xmlns="http://schemas.microsoft.com/phone/2013/windowsphonereservedappinfo">
  <SoftwareCapabilities>
    <SoftwareCapability Id="ID_CAP_VOIP" />
  </SoftwareCapabilities>
</WindowsPhoneReservedAppInfo>

It work fine. Good luck!