Click here to Skip to main content
15,899,679 members
Please Sign up or sign in to vote.
1.50/5 (2 votes)
See more:
How do i play audio from my resources in c#?
Posted

Try this

C#
private void play()
{
SoundPlayer sound = new SoundPlayer(YourNameSpace.Properties.Resources.FileName);
sound.Play();
}


I found that in this blog[^]
 
Share this answer
 
Comments
[no name] 12-Feb-11 22:24pm    
I get this error

Error 2 The type or namespace name 'SoundPlayer' could not be found (are you missing a using directive or an assembly reference?) C:\Users\Kyle\AppData\Local\Temporary Projects\OneSound\Form1.cs 21 37 OneSound
Yusuf 13-Feb-11 7:56am    
See at the error you got. It is very discriptive and it tells you exactly what you need to do. Don't you agree.

PlaySound is in this namespace - System.Media
PlaySound is in this assembly - System.dll

check the reference http://msdn.microsoft.com/en-us/library/system.media.soundplayer.aspx

The rest is left to you as an exercise.
Member 8329360 25-Feb-12 13:59pm    
*descriptive, and what is it with people like you (Yusef) who can't be bothered to indicate the using statements which C# code needs, in order to compile and run? The error does *not* "tell you exactly what you need to do"
See here[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900