Search code examples
c#audioplayback

Play Sounds in a C#


I'm making a program in C# and I want to add sound effects to it. However, I have looked up countless tutorials but none of them seem to work, and gave me tons of errors. If anyone can give me a code to play a .wav file from resource files then I would be very grateful


Solution

  • How to: Play Sounds in an Application

    Add the following method code under the button1_Click event hander :

     System.Media.SoundPlayer player = 
     new System.Media.SoundPlayer();
     player.SoundLocation = @"C:\Users\Public\Music\Sample Music\xxxx.wav";
     player.Load();
     player.Play();