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,389
  • 5
  • 41
  • 48
  • possible duplicate of [Playing a .WAV file in .NET](http://stackoverflow.com/questions/1284322/playing-a-wav-file-in-net) – rinukkusu Aug 21 '14 at 09:36
  • 2
    You can script the Button.MouseUp and -Down events to start and stop. – TaW Aug 21 '14 at 10:27

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,002
  • 13
  • 52
  • 74