我希望在我的C#应用程序中播放一个MP3流。我有一个服务器应用程序,它捕获波形音频并将其转换为MP3,然后将其写入网络流中。客户端随后读取此流以播放MP3。我尝试使用下面的代码示例使用NAudio,但会导致异常:
using (WaveStream blockAlignedStream =
new BlockAlignReductionStream(
WaveFormatConversionStream.CreatePcmStream(
new Mp3FileReader(ms))))
{
using (WaveOut waveOut = new WaveOut(WaveCallbackInfo.FunctionCallback()))
{
waveOut.Init(blockAlignedStream);
waveOut.Play();
while (waveOut.PlaybackState == PlaybackState.Playing )
{
System.Threading.Thread.Sleep(100);
}
}
}