c# - UWP C# 将音频设备设备信息显示到文本块
问题描述
当我textblock
从ApplicationDataContainer
从 中选择 时listbox
,deviceId
能够正确显示在textblock
private void audioRenderList_P_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
mediaPlayer_CH1.AudioDevice = renderDeviceList_P[audioRenderList_P.SelectedIndex];
renderDeviceName_P.Text = renderDeviceList_P[audioRenderList_P.SelectedIndex].Name.ToString();
}
if (mediaPlayer_CH1.AudioDevice.Id != null)
{
Windows.Storage.ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
Windows.Storage.StorageFolder localFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
localSettings.Values["audioRenderSettings_P"] = mediaPlayer_CH1.AudioDevice.Id;
}
但是,在加载保存的音频时,deviceId
它无法显示为可读字符;
Windows.Storage.ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
Windows.Storage.StorageFolder localFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
if (localSettings.Values["audioRenderSettings_P"] != null)
{
var audioSource = localSettings.Values["audioRenderSettings_P"] as string;
mediaPlayer_CH1.AudioDevice = await DeviceInformation.CreateFromIdAsync(audioSource);
renderDeviceName_P.Text = audioSource;
}
else renderDeviceName_P.Text = "Select Audio Device ..";
请帮忙。谢谢你。
解决方案
SelectionChanged
万一,您正在显示Name并保存Id。但是在加载时,您显示的是Id,它们是不一样的。
加载时,您可以将代码更改为:
var audioSource = localSettings.Values["audioRenderSettings_P"] as string;
mediaPlayer_CH1.AudioDevice = await DeviceInformation.CreateFromIdAsync(audioSource);
renderDeviceName_P.Text = mediaPlayer_CH1.AudioDevice.Name.ToString();
此致。