Reputation: 333
So I have a simple C# program that I want to play a sound file with the name "m.wav". I add the audio file as "existing item" (in VS) and it's located in the same folder as the classes, program.cs etc (main folder/root).
Since it's located in the same directory as the rest of the files, I try to call the audio file with the following code;
System.Media.SoundPlayer player = new System.Media.SoundPlayer(); player.SoundLocation = Environment.CurrentDirectory + @"\m.wav"; player.PlayLooping();
BUT the audio file can't be found. I have an example file that does exactly the same, but it actually works. What have I done wrong?
Upvotes: 2
Views: 2390
Reputation:
Left click on your file in the Solution Explorer, then look at the Properties window (hotkey F4 by default).
There you look for a property named Copy to Output Directory and change its value to Copy always or Copy if newer.
This lets the file appear in your ouput directory (where your .exe file is) and your code should work.
Upvotes: 2