Playing audio to the earpiece from a Windows Phone 8.1 universal app


Some time ago I blogged about the Windows Phone AudioRoutingManager API which allows you to put a “Speakerphone” and “Bluetooth” button in your Windows Phone app.

A common question that I get now is “I’m trying to play audio to the earpiece from my app, but AudioRoutingManager::SetAudioEndpoint(AudioRoutingEndpoint_Earpiece) is failing.”

It’s an interesting question, because Windows Phone will automatically route your audio to the earpiece if you have everything set up right – and if you don’t have everything set up just right, you can’t route it to the earpiece at all!

So how do you “set things up right?”

There are two things you have to do.

  1. Tag the audio in question as “communications”
  2. Tag your app as either a “voice over IP” app or a “voicemail” app

If you do both of these things, audio will flow to the earpiece automatically – no call to SetAudioEndpoint needed.

(At this point, if you want to get fancy, you can put a “Speakerphone” in your app and wire it up to a call to SetAudioEndpoint(AudioRoutingEndpoint_Speakerphone), but that’s up to you.)

Let’s look at the two things in a little more detail.

Tag the audio in question as “communications”

How to do this depends on what API you’re using. It could be as simple as <audio src=”…” msAudioCategory=”communications” msAudioDeviceType=”communications” />. Or you might have to call IAudioClient2::SetClientProperties with an AudioClientProperties structure whose AudioClientProperties.eCategory = AudioCategory_Communications.

Tag your app as “voice over IP” or “voicemail”

You’ll need to set either the ID_CAP_VOIP or ID_CAP_VOICEMAIL Phone capability on your app. (The docs reference an ID_CAP_AUDIOROUTING capability, but that doesn’t exist.)

If you’re writing a Silverlight app, you can do that directly in the manifest.

If you’re writing a Windows Phone 8.1 (non-Silverlight) or Universal app, you have to create a WindowsPhoneReservedAppInfo.xml file and add it to your application package. It should look like this.

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

Comments (0)

Skip to main content