我想在我的 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);
}
}
}