acmstreamheader dispose was not called

Apr 7, 2012 at 12:06 PM
Edited Apr 7, 2012 at 12:13 PM

I followed the tutorial:

http://naudio.codeplex.com/wikipage?title=MP3

But it gives me that error "acmstreamheader dispose was not called".

 

I found this on google:

http://efreedom.com/Question/1-6361202/Getting-Error-Exiting-Program-Loading-Wav-Using-NAudio

But that doesn't solve my problem either.

 

My code (the Dispose() is called in the Form.Closing event):

 

        WaveChannel32 volumeStream;
        private WaveStream CreateInputStream(string fileName)
        {
            WaveChannel32 inputStream;
            if (fileName.EndsWith(".mp3"))
            {
                WaveStream mp3Reader = new Mp3FileReader(fileName);
                inputStream = new WaveChannel32(mp3Reader);
            }
            else
            {
                throw new InvalidOperationException("Unsupported extension");
            }
            volumeStream = inputStream;
            return volumeStream;
        }

        public void Dispose()
        {
            if (waveOutDevice != null)
            {
                waveOutDevice.Stop();
            }
            if (mainOutputStream != null)
            {
                // this one really closes the file and ACM conversion
                volumeStream.Close();
                volumeStream = null;
                // this one does the metering stream
                mainOutputStream.Close();
                mainOutputStream = null;
            }
            if (waveOutDevice != null)
            {
                waveOutDevice.Dispose();
                waveOutDevice = null;
            }
        }

        IWavePlayer waveOutDevice;
        WaveStream mainOutputStream;
        public void PlayMusic(string name)
        {
            if (SettingsMgr.Instance.PlayMusic)
            {
                //BGMusicPlayer.URL = string.Format("{0}{1}", MusicFolder, name);


                mainOutputStream = CreateInputStream(string.Format("{0}{1}", MusicFolder, name));

                waveOutDevice = new WaveOut();
                waveOutDevice.Init(mainOutputStream);
                waveOutDevice.Play();
            }
        }

 

 

I just need to be able to play a looping background song and play multiple sound effects (simultaneously) for a small Logitech card game. I don't need all the other fancy stuff.

Coordinator
Apr 16, 2012 at 7:36 AM

you need to make sure you call Dispose once for every call to PlayMusic