0

I am using NAudio to play music in my c++ app in VS2010:

waveOutDevice = gcnew WaveOut();
volumeStream = gcnew WaveChannel32(gcnew Mp3FileReader("C:\\file.mp3"));
mainOutputStream = volumeStream;

waveOutDevice->Init(mainOutputStream);
waveOutDevice->Play();

And it works fine, but in the end I have to make a clean up. Actually, I must dispose() IWavePlayer (waveOutDevice in the code). But Dispose() and Finalize() are not members of IWavePlayer (error C2039). If I don't dispose it, app gives me an error that WaveOut devise was not closed. How to close it?

Roman R.
  • 68,205
  • 6
  • 94
  • 158
iamnp
  • 510
  • 8
  • 23

1 Answers1

0

WaveOut class does call waveOutClose API in its Dispose method, so you could and you perhaps should complete the playback cleanly. If your point of concern is that you only hold IWavePlayer pointer, and not WaveOut, then why don't you hold the two so that you could do the proper termination.

Roman R.
  • 68,205
  • 6
  • 94
  • 158
  • anyway, waveOutDevice is now of WaveOut type, but dispose and finalize are not members – iamnp Oct 06 '12 at 13:05
  • Before posting my answer I looked into NAudio source to make sure that they are. – Roman R. Oct 06 '12 at 13:08
  • `WaveOut^ waveOutDevice;`, `waveOutDevice->Dispose();`? I am getting C2039 with that code. – iamnp Oct 06 '12 at 13:18
  • `delete` it to have Dispose called for you, [#1](http://msdn.microsoft.com/en-us/library/ms177197%28v=vs.100%29.aspx) and [#2](http://weblogs.thinktecture.com/cnagel/2006/04/ccli-finalize-and-dispose.html). – Roman R. Oct 06 '12 at 13:31