private void DoPlayback()
{
var waitTime = TimeSpan.FromSeconds((double)this.buffers[0].BufferSize / (this.waveStream.WaveFormat.AverageBytesPerSecond * 2));
while (playbackState != PlaybackState.Stopped)
{
if (callbackEvent.WaitOne())
{
// requeue any buffers returned to us
if (playbackState == PlaybackState.Playing)
{
int queued = 0;
foreach (var buffer in buffers)
{
if (buffer.InQueue || buffer.OnDone())
{
queued++;
}
}
if (queued == 0)
{
// we got to the end
this.playbackState = PlaybackState.Stopped;
}
}
}
}
}