我正在尝试设置c#中媒体元素的来源。这就是我要做的
XAML Part
<MediaElement x:Name="Sound" AutoPlay="False" />
<Button Content="Shout!" Height="123" Name="button2" Width="123" Click="shout_Click" />
<<p> c#部分/strong> private void shout_Click(object sender, RoutedEventArgs e)
{
this.Sound.Source = new Uri("Sounds/fusrodah.wma", UriKind.Relative);
this.Sound.Play();
}
以上内容不起作用。但是,如果我在xaml中手动设置路径,它可以工作。如何在c#中设置a MediaElement
的源?
你得到一个错误,还是它只是不播放?尝试添加一个正斜杠,Dovahkiin:
this.Sound.Source = new Uri("/Sounds/fusrodah.wma", UriKind.Relative);