Question

I have stored an audio file in the resources folder of my application but when I use the below path I get a file no found exception.

Can someone explain if this is the correct way to reference a file in resources or if I need to set the path differently?

This is the code that take the audio file as a parameter:

SoundPlayer player = new SoundPlayer("Resources/Audio/punchSound.wav");
player.Load();
player.Play();

enter image description here

Was it helpful?

Solution

You can use resource string:

var music = Properties.Resources.punchSound;

And then use SoundPlayer like this:

var player = new SoundPlayer(new MemoryStream(music));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top