This project has moved and is read-only. For the latest updates, please go here.

WaveOut callback with existing window bug

Dec 29, 2011 at 5:46 PM

I am currently working on my own implementation of the waveout api because i want to understand how naudio works and so on... :)

So I've reached a point now where everything with waveout works really fine. But I have a little problem that I can't fix. So I had a look on the naudio source. The source naudio is very different (may a bit better) but there is also the same problem. So I've written a little example where the bug occours.
The Problem ist you can't dispose and create a new WaveOut device in a small time.

Try out this code:

WaveOut waveOut;
        private void button1_Click(object sender, EventArgs e)
            OpenFileDialog ofn = new OpenFileDialog();
            if (waveOut != null)

            waveOut = new WaveOut(this.Handle);
            Mp3FileReader reader = new Mp3FileReader(ofn.FileName);

If you try out this code you will get a object is null exception. I fixed that but after that there will be other problems like you are opening a new waveout while closing the old one...

So is there a way to fix that problem. I had a look on that for now more than 2 hours but I found no solution.

btw. it is very very interesting what is behind this greate libary.^^

Dec 29, 2011 at 5:52 PM

this situation is what the NewWindow callback was created for. Essentially if you use the same window handle, you end up processing callbacks for the wrong instance of WaveOut.

BTW, what version of NAudio are you using?


Dec 29, 2011 at 9:18 PM

hmm i don t know exactly what version i am using but it is between 2 and 4 days old.

By the way thank you for the quick and great answer :)