after recording. application can't read file

Apr 9, 2010 at 9:14 AM

I want show waveform after finish recording. so I use wavecontrol_demo to draw waveform but system throw "it is being used by another process."

I think file handle can't release. I didn't find a function to release its handle after waveIn.StopRecording() was call. can everybody give me an suggestion?

ps: I can draw waveform without any problem when not recording.

Coordinator
Apr 15, 2010 at 4:01 PM

have you Disposed of your WaveFileWriter class?

Mark

Apr 17, 2010 at 7:32 AM

I'm using NAudio.dll in my project and I believe it has included disposed.

Coordinator
Apr 17, 2010 at 8:04 AM

can you share any of the source code you are using?

Mark

Apr 19, 2010 at 2:26 AM

private void btnPlayStop_Click(object sender, EventArgs e)
        {
            if (btnPlayStop.Text == "Play")
            {
                if (outputFilename != "")
                {
                    Process.Start(outputFilename);
                }
            }
            else// click stop -- save  recording and draw waveform
            {
                btnPlayStop.Text = "Play";

                StopRecording();

                if (outputFilename != "") // draw waveform
                {
                   waveControl1.Filename = outputFilename;
                   waveControl1.Read(); <-- line error . cause output file be process by another process.
                }
            }
        }

private void StopRecording()
        {
            waveIn.StopRecording();
        }

Apr 19, 2010 at 2:43 AM

Thank Mark. I think I found out the reason. I should put draw command in RecordingStopped events after writer.close();

private void waveIn_RecordingStopped(object sender, EventArgs e)
        {
            if (this.InvokeRequired)
            {
                this.BeginInvoke(new EventHandler(waveIn_RecordingStopped), sender, e);
            }
            else
            {
                waveIn.Dispose();
                writer.Close();
                //generate waveform
                if (outputFilename != "")
                {
                    waveControl1.Filename = outputFilename;
                    waveControl1.Read();
                }
                btnRecord.Enabled = true;
                prgMic.Value = 0;
            }
        }

Coordinator
Apr 19, 2010 at 1:50 PM

glad you got it working

Mark