0

I am looking for a way to turn an ordinary C# Winform button into a sort of push button to play a wav file when pressed and held in and pause it when you release the button.

Is there an easy way of doing this?

Daniel Kelley
  • 7,579
  • 6
  • 42
  • 50

1 Answers1

0

Simply play the file when the mouse is down and stop the player when the mouse is up again:

SoundPlayer soundPlayer = new SoundPlayer(pathToWavFile);

private void yourButton_MouseDown(object sender, MouseEventArgs e) {
    soundPlayer.Play();
}
private void yourButton_MouseUp(object sender, MouseEventArgs e) {
    soundPlayer.Stop();
}
Manuel Allenspach
  • 12,467
  • 14
  • 54
  • 76