tags:

views:

145

answers:

2

It's fairly simple to play a sound file, say temp.wav, from Visual Studio C#. I'm looking for a way to do this without temp.wav being locatable from the machine running the program.

IE - I want to read the .WAV file into my solution so that it is somehow inside of my .EXE and be played by it.

Is this possible?

+4  A: 

you need to load it as a resource. Add the wav file to your project in the resources folder. And select to embed it in the properties editor, I think it's the build action property.

HollyStyles
This is exactly what I was thinking.
Jaxidian
I'm looking at the /resource command line option right now as I am without Visual Studio right at this moment.
HollyStyles
+2  A: 

First add the .wav file as a resource: Project + Properties, Resources tab, click on the arrow of "Add Resource", Add Existing File and navigate to your wav. Let's say it is called "Beep".

Then add code like this to play the sound:

    private void button1_Click(object sender, EventArgs e) {
        new System.Media.SoundPlayer(Properties.Resources.Beep).Play();
    }
Hans Passant
System.Media.SoundPlayer!! cool I was still using [DllImport("Winmm.dll")] things move too fast in this game :)
HollyStyles