I followed the tutorial on NAudio's website on how to load and play an mp3 file, but even though I put the audio file in the right directory, whenever I run, the program crashes with "vshost32.exe has stopped working." Any ideas? I'm using Visual Studio 10.0 on Windows 7.
Here's the (exact) code that the tutorial gave me:
namespace NAudioTest
{
class Program
{
static IWavePlayer waveOutDevice;
static WaveStream mainOutputStream;
static WaveChannel32 volumeStream;
static void Main(string[] args)
{
waveOutDevice = new WaveOut();
mainOutputStream = CreateInputStream("Kalimba.mp3");
waveOutDevice.Init(mainOutputStream);
waveOutDevice.Play();
}
private static WaveStream CreateInputStream(string filename)
{
WaveChannel32 inputStream;
if (filename.EndsWith(".mp3"))
{
WaveStream mp3Reader = new Mp3FileReader(filename);
inputStream = new WaveChannel32(mp3Reader);
}
else
{
throw new InvalidOperationException("Unsupported extension");
}
volumeStream = inputStream;
return volumeStream;
}
}
}
(sorry for the poor formatting)