首页 > 解决方案 > UWP C# 将音频设备设备信息显示到文本块

问题描述

当我textblockApplicationDataContainer

从 中选择 时listboxdeviceId能够正确显示在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 ..";

在此处输入图像描述

请帮忙。谢谢你。

标签: c#xamluwpraspberry-pi3windows-iot-core-10

解决方案


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();

此致。


推荐阅读