I want to include a functionality in my application such that when the user clicks on a button, the user should be able to record the voice, and when stopped, the sound should be saved. Here's what I wrote for the Start and Stop button
private void button1_Click(object sender, EventArgs e)
Button btnStrtStop = (Button)sender;
if (i == 0)
btnStrtStop.BackgroundImage = System.Drawing.Image.FromFile("RecordPressed.png");
mciSendString("Open new type waveaudio alias RecSound", "", 0, 0);
mciSendString("Record Recsound", "", 0, 0);
i = 1;
string strAppDir = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetModules().FullyQualifiedName);
btnStrtStop.BackgroundImage = System.Drawing.Image.FromFile("RecordHot.png");
mciSendString("Save RecSound" + strAppDir + "record.wav", "", 0, 0);
mciSendString("Close RecSound", "", 0, 0);
i = 0;
The problem I am facing is that the background image is not find the backgournd image for Start Stop button. I am not using the Open File Dialog but I have the two png files in the project directory itself.
For the play button, I have used
System.Media.SoundPlayer myPlayer = new System.Media.SoundPlayer();
myPlayer.SoundLocation = @"c:\file.wav";
I would have to load the file from the same path in the debug folder. how to specify that?
Also, unlike the previous code in the filename is constant "file.wav ", I want to provide a custom filename for each file we save.