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);
}
}
}
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.
来源:https://stackoverflow.com/questions/5160195/how-to-play-an-mp3-stream-in-c-sharp