3

I am trying to set a filepath for a SoundPlayer object

If I have a sounds folder in my main project folder. How do I go about sending

Soundplayer test = new Soundplayer("Sounds/Fireball.wav"); 
1
  • 3
    eh... say WHAT ? what is Soundplayer, what isn't working, what is happening and what did you expect to happen? Commented Dec 13, 2010 at 21:53

3 Answers 3

6

Where the file is relative to your main project is not important. What's important is where will the sound file be relative to your application at deployment / debug time. If it will have the same relative path as that of the main .exe path then you can use the following.

var root = typeof(Program).Assembly.Location; var soundPath = Path.Combine(root, @"sounds\Fireball.wav"); var test = new SoundPlayer(soundPath); 
Sign up to request clarification or add additional context in comments.

Comments

1

Have you tried the path as @"Sounds\Fireball.wav"?

Comments

1

If you are running out of Visual Studio, the current working directory will be bin\Debug, so the file in question would need to be in bin\Debug\Sounds\Fireball.wav.

Also, as others have mentioned, you should use backslash \ rather than forwardslash /

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.