0
votes

I want my sound to play when I click a button. the sound file will play but will only play once. I need it to play everytime i hit a button. please help.

Heres what i have so far::

XAML:

MediaElement x:Name="SoundClip" Source="Dart.mp3" AutoPlay="False" />

C#:

    private void OutBull_Click(object sender, RoutedEventArgs e)
    {
        SoundClip.Play();
        game.update_score(25);
        updateGUI();
    }

    private void Bull_Click(object sender, RoutedEventArgs e)
    {
        SoundClip.Play();
        game.update_score(50);
        updateGUI();
    }

I need all these to play the sound when i click them. Not just once in which it only does?????

3

3 Answers

0
votes

If you set the MediaEnded event as below it should work.

private void SoundClip_MediaEnded(object sender, Windows.UI.Xaml.RoutedEventArgs e) {
  SoundClip.Stop();
 }
0
votes

SoundPlayer is only supposed to be compatible with .wav files. Have you attempted to convert your .mp3 file to a .wav file? It may be causing the SoundPlayer to stop working after the first time it plays the file due to the lack of compatibility.

0
votes

So in your HTML code there should be an or something that you can set to reset

This is java but if you google onclick reset it should help.

<br>
<input type="reset" name=resetbutton value=Reset
   onClick='alert("The reset button was clicked")'>
<br>

Reset the buttons at the end so the next time you click it, the methods get passed to the button again.

Should work