如何仅在 Windows Phone 8 应用程序中通过听筒播放音频 [英] how to play audio through earpiece only in windows phone 8 application
本文介绍了如何仅在 Windows Phone 8 应用程序中通过听筒播放音频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试过使用 AudioRoutingManager 类...但我遇到了未经授权的访问异常.这是我的代码
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());
}
推荐答案
Windows.Phone.Media.Devices 命名空间中的 API 需要 ID_CAP_AUDIOROUTING 和 ID_CAP_VOIP 功能.(将此添加到您的清单中)
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)
此外,只能在正在进行的 VOIP 通话中更改音频路由.
Also, it's only possible to change the audio routing while in a active VOIP call.
此外,您需要在后台 VOIP 进程中进行音频路由,而不是在前台进程中.
Additionally, you need to do the audio routing in your background VOIP process, and not in the foreground process.
这篇关于如何仅在 Windows Phone 8 应用程序中通过听筒播放音频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文