1

I am making a piano app, where each key plays a different .wav file. For instance, if the C note is pressed then C.wav is played.

So far I have only managed to play a wav file using the code in the screenshot, otherwise the file is not found. However this method is not suitable for what I am trying to do. The wav file i am trying to play is called hello.wav and I have provided the location. Any suggestions?

This is the current code:

SoundPlayer sp = new SoundPlayer(PianoApp.Properties.Resources.Hello);
sp.Play();

or as it appears in my IDE:

current code

This is the file location:

file location

doppelgreener
  • 4,809
  • 10
  • 46
  • 63
Mar
  • 13
  • 6

2 Answers2

0

If your problem is to find your files in the output folder of your application, then just set the "Copy to Output Directory" option to "Copy always" in the Properties window. But if you want to keep them in resources, then you can also use Properties.Resources.ResourceManager.GetStream("audioResourceName") to get your audio files according to a particular key name that was pressed. Thus, you should name all your resources accordingly.

Oleg Safarov
  • 2,325
  • 14
  • 19
0

I,

Add you your file .wav in ressource of your project with mySoundFile as name, and code like this

 Stream str = Properties.Resources.mySoundFile;
 SoundPlayer snd = new SoundPlayer(str);
 snd.Play();

with multiple .wav ressources

 Stream str1 = Properties.Resources.mySoundFile1;
 Stream str2 = Properties.Resources.mySoundFile2;

 RecordPlayer rp = new RecordPlayer();
 rp.Open(new WaveReader(str1));
 rp.Play();

 rp.Open(new WaveReader(str2));
 rp.Play();
Esperento57
  • 16,521
  • 3
  • 39
  • 45