-3

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";
        sndPlayer.PlayLooping();

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 :)

Toortelz
  • 9
  • 2

1 Answers1

0

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";
Hatted Rooster
  • 33,170
  • 5
  • 52
  • 104