This project has moved. For the latest updates, please go here.

Playing online radio using c#

Oct 17, 2010 at 11:47 AM
Edited Oct 17, 2010 at 1:24 PM

Hi, i'm trying to make my own music player, and i'd like to add function which will play online radio.

I've only found code which play MP3FromURL :

public static void PlayMp3FromUrl(string url)
            using (Stream ms = new MemoryStream())
                using (Stream stream = WebRequest.Create(url)
                    byte[] buffer = new byte[32768];
                    int read;
                    while ((read = stream.Read(buffer, 0, buffer.Length)) > 0)
                        ms.Write(buffer, 0, read);

                ms.Position = 0;
                using (WaveStream blockAlignedStream =
                    new BlockAlignReductionStream(
                            new Mp3FileReader(ms))))
                    using (WaveOut waveOut = new WaveOut(WaveCallbackInfo.FunctionCallback()))
                        while (waveOut.PlaybackState == PlaybackState.Playing)

Also there is similar topic here :

But it has no answer too.

Can anyone help me with this?


Nov 4, 2010 at 7:47 PM

NAudio doesn't have built-in support for playing over the network, but it has the basic building blocks needed to set this up.

Currently the MP3 file reader does some seeking in the constructor, which means you need to pre-download the whole file. I am hoping to eliminate this in the near future.