This worked for me to play a wav file:
using NAudio.Wave;
.....
var soundFile = "Something.wav";
using (var wfr = new WaveFileReader(soundFile))
using (WaveChannel32 wc = new WaveChannel32(wfr) {PadWithZeroes = false})
using (var audioOutput = new DirectSoundOut())
{
audioOutput.Init(wc);
audioOutput.Play();
while (audioOutput.PlaybackState != PlaybackState.Stopped)
{
Thread.Sleep(20);
}
audioOutput.Stop();
}
In this case, the PlaybackStopped event was raised, but I guess it's not good to count on that.
This would work when running as a service on Windows 7.
↧