I am having some issue to display my saved USB Audio Adapter name on a textblock
when i load it from ApplicationDataContainer
when selecting the from the listbox
, the deviceId
is able to be displayed properly on the 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;
}
However, when loading of saved audio deviceId
it couldn't be displayed as readable characters;
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 ..";
Please help. Thank you.
In SelectionChanged
event, you are displaying the Name and saving the Id. But when loading, you are showing Id, they are not same.
When loading, you can change code to:
var audioSource = localSettings.Values["audioRenderSettings_P"] as string;
mediaPlayer_CH1.AudioDevice = await DeviceInformation.CreateFromIdAsync(audioSource);
renderDeviceName_P.Text = mediaPlayer_CH1.AudioDevice.Name.ToString();
Best regards.