Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I play a sound in WinForms?

Tags:

c#

winforms

audio

How can I play a sound in WinForms with C#?

like image 492
Moon Avatar asked Aug 20 '09 05:08

Moon


People also ask

How do I play a video in Windows Forms?

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.

Is WinForms going away?

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.


2 Answers

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();
like image 67
Karl Johan Avatar answered Nov 09 '22 02:11

Karl Johan


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

like image 9
Sebastian Gray Avatar answered Nov 09 '22 02:11

Sebastian Gray