I built a simple example (following your code) and everything should be fine. Just to make sure everything is in order, I will do a few checks as described below:
In XAML:
<Button x:Name="myButton" VerticalAlignment="Cener" Content="BEEP"/>
<MediaElement Name="beep" Source="beep.mp3" Volume="1" AutoPlay="False" MediaFailed="beep_MediaFailed" MediaOpened="beep_MediaOpened"/>
Code behind:
public MainPage()
{
InitializeComponent();
myButton.Click += (sender, e) => { beep.Play(); };
if (Application.GetResourceStream(new Uri("beep.mp3", UriKind.Relative)) == null)
MessageBox.Show("File not Exists!");
}
private void beep_MediaFailed(object sender, ExceptionRoutedEventArgs e)
{
MessageBox.Show("There was an error: " + e.ErrorException.Message);
}
private void beep_MediaOpened(object sender, RoutedEventArgs e)
{
beep.Play();
MessageBox.Show("Media opened");
}
- , beep.mp3 (, ). , . (Failed/Opened). , .mp3.
, , , beep.Play() InitializeComponent, , , - , (, , , , ).
, , , WiredPraire ( ) SoundEffect .
, .