Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Playing wav file which has relative path inside project

I have some problems with relative paths and reproduction of wav files. I have this simple code which works perfectly:

SoundPlayer player = new SoundPlayer();
player.SoundLocation = @"C:\Users\Admin\Documents\Visual Studio 2012\Projects\TestProject\TestProject\Data\Sounds\car.wav";
player.Play();

I want somehow to play that file with relative path but I didn't have success with this:

SoundPlayer player = new SoundPlayer();
player.SoundLocation = @"Data\Sounds\car.wav";
player.Play();

Thank you!

like image 575
Cristiano Avatar asked Apr 17 '13 16:04

Cristiano


2 Answers

Is Data directory in the root directory of your application? Are you copying the directory contents as output?

If so, did you mean, Data\Sounds\car.wav?

Which, if running from Visual Studio would be in [projectroot]\[release]\bin\Data\Sounds\car.wav

If you don't see this directory in your bin folder, you'll need to ensure you're selecting all of the files you want copied to your output directory (which will copy the directory structure). You can do this by clicking on the file in your project and selecting the file as output.

like image 99
George Johnston Avatar answered Oct 30 '22 15:10

George Johnston


Get the full path of your file with Path.GetFullPath("relativ/path")

like image 2
Sir l33tname Avatar answered Oct 30 '22 16:10

Sir l33tname