This project has moved. For the latest updates, please go here.

Proper cleanup of NAudio objects

Jan 26, 2011 at 9:53 AM
Edited Jan 26, 2011 at 10:10 AM


I'm having a problem when disposing of NAudio objects (waveplayer, wavestream etc.).  I get an "Assertion Failed" popup window with the message "AcmStreamHeader dispose was not called". This happens only when I play MP3 sources (from a Stream object) and otherwise works fine with WAVs. I can reproduce the error either by playing multiple instances in succession or after I close the application, in which case the popup appears only momentarily and closes on its own.

My code is such that only one WavePlayer and WaveStream are active at any one time and I dispose and recreate in between successive playing. I also ensure that the objects are disposed on closing of the play dialog form.

I should also point out that I create intermediate streams to normalise to PCM format and 16bit sample depth where needed, hence these would presumably create other wavestream instances that I don't explicitly dispose.

Could you please direct me on which objects I should keep track of and dispose (and in which order)?



EDIT: Turns out I had a bug and was not disposing the wavestream. Apparently it is sufficient to dispose the one that is fed to the WavePlayer object.