Playing a WAV

Last edited Dec 30, 2010 at 11:11 AM by OpenSebJ, version 1

Comments

wtheronjones Mar 7, 2013 at 7:16 PM 
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.

wtheronjones Mar 2, 2013 at 12:32 AM 
Could someone be a lamb and post a sample? I need to play a WAV file from a Windows Service on Windows 7 and this is supposed to be the solution to my problems.

jjxtra Feb 13, 2013 at 12:35 AM 
So... is this page going to be updated ever?