簡體   English   中英

UWP C# 將音頻設備設備信息顯示到文本塊

[英]UWP C# To Display AudioDevice DeviceInformation to Textblock

當我從ApplicationDataContainer加載它時,我在文本塊上顯示我保存的textblock音頻適配器名稱時遇到一些問題

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

此致。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM