Can you find a .wav file in the 'Debug' folder of the console project?
- What I need to happen -
I am trying to play a looping .wav file in my game (it is a Console project, NOT Forms), and I need to find the .wav file even when the code runs on any computer. For example, if I put my game on a USB and run it on a different computer, the code needs to locate the .wav file in the project folder.
- The problem -
At the moment my code looks like this:
static void Main(string[] args)
{
var soundPlayer = new System.Media.SoundPlayer();
soundPlayer.SoundLocation = @"C:\ProjectFolder\song.wav";
soundPlayer.PlayLooping();
}
This does play my .wav file but if I take it to another computer, it tries to find the .wav file on my HDD, not on the new computers HDD/ SSD.
- What I have tried -
I have looked and every answer I have found doesn't work. This is one answer that is supposed to work but doesn't:
static void Main(string[] args)
{
var soundPlayer = new System.Windows.Media.MediaPlayer();
soundPlayer.Open(new Uri(Application.StartupPath + @"\ProjectFolder\song.wav"));
soundPlayer.PlayLooping();
}
In the Visual Studio editor, 'Media' on line 1 is underlined red and so is 'Application' on line 2.
- HELP! -
I hope this is a common problem and all of you that are much better coders than I can find the answer. Please it would be very helpful if you could comment below, even if you know anything related to this or could point me to someone who does know. Thank you for reading.