HawaiiDragon
asked on
Playing a sound on a button click in a windows program C#
Hi all:
Im trying to play a spcific sound on a button click. I have tried creating a method to do so but its not working. Any help would be great.
Im trying to play a spcific sound on a button click. I have tried creating a method to do so but its not working. Any help would be great.
ASKER
not really.... unfortunaly
ok
ASKER
it works in his soluition but not mine.... quite annoying
Assuming the wav file is in the same folder as your EXE:
private void button1_Click(object sender, EventArgs e)
{
System.Media.SoundPlayer sp = new System.Media.SoundPlayer(" yeehaw.wav ");
sp.Play();
}
See SoundPlayer():
http://msdn.microsoft.com/en-us/library/system.media.soundplayer(VS.80).aspx
private void button1_Click(object sender, EventArgs e)
{
System.Media.SoundPlayer sp = new System.Media.SoundPlayer("
sp.Play();
}
See SoundPlayer():
http://msdn.microsoft.com/en-us/library/system.media.soundplayer(VS.80).aspx
ASKER
okay how do I add the sound clip "whip.wav" as a resource becasue I still cant get it to work.
ASKER
please see the doc file for full details. Let me know what ive done wrong I feel like such an idiot.
problems.doc
problems.doc
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Your a god. Now my question is why did this work and not the others. Is it because I did not make it an embedded resource? Anything I can learn is appriciated.
With my previous submission, the wav file would have to be physically located in the same folder as the running .net exe. As an embedded resource it is contained within the EXE and always there.
Does this help?
http://www.eggheadcafe.com/articles/20030302.asp