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

为君一笑 提交于 2019-11-28 01:16:14

问题


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


回答1:


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.




回答2:


Old question but now I know the answer.

Two things which you need to do: 1. Tag the audio in question as "communications"

How to do this depends on what API you're using. It could be as simple as . Or you might have to call IAudioClient2::SetClientProperties with an AudioClientProperties structure whose AudioClientProperties.eCategory = AudioCategory_Communications.

  1. Tag your app as either a "voice over IP" app or a "voicemail" app You should add file called WindowsPhoneReservedAppInfo.xml to your project with the following contents:

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

Look for more detailed explanation here:

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



来源:https://stackoverflow.com/questions/14685019/how-to-play-audio-through-earpiece-only-in-windows-phone-8-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!