How to play an MP3 stream in C#

吃可爱长大的小学妹 提交于 2019-12-19 04:04:39

问题


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);
                    }
                }
            }

回答1:


http://www.un4seen.com/

bass.dll .NET api

i know its not the answer to your code but its a good music library




回答2:


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!