Reputation: 397
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?
Upvotes: 2
Views: 2523
Reputation: 941277
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();
}
Upvotes: 3
Reputation: 5039
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.
Upvotes: 4