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

Proper cleanup of NAudio objects

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

Hi,

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)?

Thanks

 

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.