Toortelz Toortelz - 1 year ago 87
C# Question

Using audio file in c# console application

I'm making a text based game on cmd using c#, and I need your help.

I'm using this code for playing audio:

SoundPlayer sndPlayer = new SoundPlayer();
sndPlayer.SoundLocation = @"C:\Users\Uri\Desktop\Music\Music for game\sp8.wav";

But the problem is that for this to work on other computers theres need to be an audio file in the exact same spot it is on my computer.

I know there are solutions to this online, but as a newbie and a guy whose native language isn't english, I don't really understand them.

Is anyone kind enough to guide me step-by-step on how to make this work on other computers too?

Thanks a lot :)

Answer Source

You use a relative path and ship that with your game.

For example, you ship your game with the executable and some folder with sounds where you add your sounds. You can then use a relative path to access them :

sndPlayer.SoundLocation = @"sounds\sp8.wav";