我正在尝试通过单击按钮功能播放音频文件。我试过这个代码,但它不起作用。如何在代码隐藏中播放音频文件?
public static List<string> audiofiles = new List<string>();
public static string sound1 = (new Uri("/Assets/Audio/baby-crying-01.wav", UriKind.Relative)).ToString();
public static string sound2 = (new Uri("/Assets/Audio/baby-crying-02.wav", UriKind.Relative)).ToString();
public static string sound3 = (new Uri("/Assets/Audio/baby-crying-03.wav", UriKind.Relative)).ToString();
public static string sound4 = (new Uri("/Assets/Audio/baby-crying-04.wav", UriKind.Relative)).ToString();
public static string[] sounds_list = new string[4];
private void Practice_Click(object sender, RoutedEventArgs e)
{
this.LayoutRoot.Children.Add(music);
audiofiles.Add(sound1);
audiofiles.Add(sound2);
audiofiles.Add(sound3);
audiofiles.Add(sound4);
for (i = 0; i < 4; i++)
{
sounds_list = audiofiles.ToArray();
music.Source = new Uri(sounds_list[i], UriKind.Relative);
music.Play();
}
}