如何在 C# 中播放 MP3 流
我想在我的 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);
}
}
}
I want to play an MP3 stream in my C# application. I have a server application that captures wave audio and converts it into MP3, then writes it to a network stream. The client then reads this stream to play the MP3. I have tried NAudio with the following code example, but it results in exception:
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);
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
http://www.un4seen.com/
bass.dll .NET api
我知道它不是您的答案代码,但它是一个很好的音乐库
http://www.un4seen.com/
bass.dll .NET api
i know its not the answer to your code but its a good music library
我在我的博客上发布了一篇文章解释 如何使用 NAudio 播放 MP3 流。本质上,您有一个线程下载 MP3 帧、解压缩它们并将它们存储在 BufferedWaveProvider 中。然后另一个线程使用 BufferedWaveProvider 作为输入进行播放。
I have posted an article on my blog explaining how to play back an MP3 stream using NAudio. Essentially you have one thread downloading MP3 frames, decompressing them and storing them in a
BufferedWaveProvider
. Another thread then plays back using theBufferedWaveProvider
as an input.