Search code examples
audionaudio

NAudio - WaveOut doesn't raise PlaybackStopped event when used with WaveOffsetStream


When you create a WaveOut object, and initialize it with WaveOffsetStream, the PlaybackStopped event is not raised at the end of the playback. Code:

WaveOut myWaveOut = new WaveOut();
myWaveOut.PlaybackStopped += OnPlaybackStopped;

WaveOffsetStream OffsetStream = new WaveOffsetStream(MyOtherStream);

myWaveOut.Init(OffsetStream);
myWaveOut.Play();

Solution

  • WaveOutOffsetStream always returns the requested number of bytes from Read so it is a never-ending stream. You'd have to use something different, or detect when the Position went past the point you wanted to play to