how to play audio through earpiece only in windows phone 8 application

windows-phone-8, windows-phone-voip

Solution

The APIs in the Windows.Phone.Media.Devices namespace require the ID_CAP_AUDIOROUTING and the ID_CAP_VOIP capability. (Add this to your manifest)

Also, it's only possible to change the audio routing while in a active VOIP call.

Additionally, you need to do the audio routing in your background VOIP process, and not in the foreground process.

Problem

I have tried with AudioRoutingManager class...but i got unauthorizedaccess exception. here is my code ``` AudioRoutingManager audioRouting = AudioRoutingManager.GetDefault(); public AudioRoutingEndpoint ChangeAudioRoute() { var currentEndPoint= audioRouting.GetAudioEndpoint(); switch (currentEndPoint) { case AudioRoutingEndpoint.Earpiece: case AudioRoutingEndpoint.Default: return AudioRoutingEndpoint.Speakerphone; case AudioRoutingEndpoint.Speakerphone: return AudioRoutingEndpoint.Earpiece; default: throw new OperationCanceledException(); } } public void SetAudioRoute() { audioRouting.SetAudioEndpoint(this.ChangeAudioRoute()); } ```

Original source