Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
894 views
in Technique[技术] by (71.8m points)

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...