Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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());
    }

enter image description here

like image 786
user1934329 Avatar asked Feb 04 '13 10:02

user1934329


1 Answers

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.

like image 65
Patrick F Avatar answered Sep 19 '22 20:09

Patrick F