How to play an MP3 stream in C#
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);
}
}
}
http://www.un4seen.com/
bass.dll .NET api
i know its not the answer to your code but its a good music library
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 the BufferedWaveProvider
as an input.
精彩评论