[英]Detect headphones in windows phone 8.1
對於我的Windows Phone 8.1 RT應用程序,我需要檢測是否插入了耳機。
我發現了以下問題,可以為Windows Phone 8.0和Windows Phone 8.1 Silverlight應用程序解決此問題: Windows Phone-音頻端點設備
它在我的主視圖(實際上是從http://developer.nokia.com/community/wiki/How_to_detect_the_audio_path_(headset_connection)_on_Windows_Phone復制)的代碼后面嘗試了以下代碼:
AudioRoutingEndpoint currentAudioRoutingEndpoint = AudioRoutingManager.GetDefault().GetAudioEndpoint();
AudioRoutingManager.GetDefault().AudioEndpointChanged += AudioEndpointChanged_Handler;
和處理程序:
private void AudioEndpointChanged_Handler(AudioRoutingManager sender, object args)
{
var audioEndPoint = sender.GetAudioEndpoint();
switch (audioEndPoint)
{
case AudioRoutingEndpoint.Default:
{
//default audio devide
break;
}
case AudioRoutingEndpoint.Earpiece:
{
//Earpiece
break;
}
case AudioRoutingEndpoint.Speakerphone:
{
//Speakerphone
break;
}
case AudioRoutingEndpoint.Bluetooth:
{
//Bluetooth
break;
}
case AudioRoutingEndpoint.WiredHeadset:
{
//WiredHeadset
break;
}
case AudioRoutingEndpoint.WiredHeadsetSpeakerOnly:
{
//WiredHeadsetSpeakerOnly
break;
}
case AudioRoutingEndpoint.BluetoothWithNoiseAndEchoCancellation:
{
//BluetoothWithNoiseAndEchoCancellation
break;
}
default:
throw new ArgumentOutOfRangeException();
}
}
如果我運行此代碼,則會收到以下異常:用戶代碼未處理System.UnauthorizedAccessException HResult = -2147024891消息=訪問被拒絕。 (來自HRESULT的異常:0x80070005(E_ACCESSDENIED))
我猜這是因為缺少所需的功能(ID_CAP_VOIP和ID_CAP_AUDIOROUTING)。 現在我的問題是,在我的Windows Phone 8.1 RT應用程序中,只有package.appxmanifest
而沒有WMAppManifest.xml
,看來我無法再定義這些功能。
請注意,我的項目中確實沒有WMAppManifest.xml
,就像在Windows Phone 8.1 Silverlight項目中一樣(實際上兩者都可用)。
我將非常感謝您的幫助!
編輯:將Windows Phone 8.1 xaml更改為Windows Phone 8.1 RT
有兩件事:
因此,您可能無法在Windows Phone上做您想做的事情(除非您正在構建VOIP應用程序)。
您想以此實現什么功能? 也許還有其他選擇。
在WP8.1 Runtime中,您可以使用以下代碼創建xml文件WindowsPhoneReserveAppInfo.xml:
<?xml version="1.0" encoding="utf-8" ?>
<WindowsPhoneReservedAppInfo xmlns="http://schemas.microsoft.com/phone/2013/windowsphonereservedappinfo">
<SoftwareCapabilities>
<SoftwareCapability Id="ID_CAP_VOIP" />
</SoftwareCapabilities>
</WindowsPhoneReservedAppInfo>
工作正常。 祝好運!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.