Try to play MP3 audio file with NAudio
I'm following this tutorial to play MP3 audio files with NAudio. To create the WaveStream I use this method:
private 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;
}
Unfortunately I always get an exception in the
line inputStream = new WaveChanne32(mp3Reader):
Blockquote
System.ApplicationException was unhandled
Message=Only PCM supported
Source=NAudio
StackTrace:
You can use
var pStream = NAudio.Wave.WaveFormatConversionStream.CreatePcmStream(mp3Reader);
var inputStream = new NAudio.Wave.BlockAlignReductionStream(pStream);
PCM is an encoding type (Pulse-code modulation). Seems like NAudio can only handle PCM encoded files.
精彩评论