How can I play a sound in WinForms with C#?
Open the ToolBox then Right-click then choose "Items" -> "COM components" then select "Windows Media Player" then click "Ok". Next it will add something from the ToolBox then drag it from the Toolbox to the form. Finally your form will look like this. Your form is now designed.
As we mentioned above, WinForms is still available but the status of “maintenance mode” likely means it has no long term future. As time passed by, especially in the last 5-10 years, new tools continued to mature and rise in popularity, and each one of them offered many powerful features.
For playing sound simply, with no interaction you can use System.Media.SoundPlayer:
System.Media.SoundPlayer player = new System.Media.SoundPlayer();
player.SoundLocation = "soundFile.wav";
player.Play();
NAudio is a great library to reproduce sound, you can find it here: http://naudio.codeplex.com/
And the tutorial is here: http://opensebj.blogspot.com/2009/02/introduction-to-using-naudio.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With