Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sound file location isn't found when run in another computer

Tags:

c#

My C# program is running well on my computer and the sound is playing, but when i sent it to my lecturer, he said the program was running but it couldn't locate my sound file. my file location in the program was like:

C:\Documents\Visual Studio 2012\Projects\Barista3000_Aroka_Lab6\Barista3000_skal\Sounds\sound.wav

How do i make sure the sound will always be located when ran on a different computer?

like image 216
Dan A Avatar asked Dec 05 '25 09:12

Dan A


1 Answers

You need to add the file to your project like and set build action to content. enter image description here

And when you build the project it will end up in your output folder, just play it with something like.

PlayFile("sound.wav"); // I made up this method btw.

Notice, not the full path to the file, this is relative and it will look for this file in the working (current) folder.

How do i make sure the sound will always be located when ran on a different computer?

For this, you will still need to distribute it with your EXE and other 'stuff' that's in your build output folder.

Also, have a look at embedding resources, that way you can include the WAV in your EXE.

like image 112
Steve Drake Avatar answered Dec 07 '25 23:12

Steve Drake



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!