Pergunta

i've readed some question,but not one solved me. i've maked a simple client to read soundstream by icecast2 server. i read sound sound with:

    a = new WMPLib.WindowsMediaPlayer();
    a.URL = "http://radiolink:8000/music";
    a.controls.play();

it's works and i ear music. now i want to read title of current song. i've found here i have to create a request like:

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://radiolink:8000/music");

            request.Headers.Clear();

            request.Headers.Add("GET", " HTTP/1.0");
            request.UserAgent = "WinampMPEG/5.09";

            request.Headers.Add("Icy-MetaData", "1");
            request.KeepAlive = true;

            WebResponse fifo = request.GetResponse();


            Console.WriteLine(fifo.Headers);

Whit thath code console write only output (content-type=audio-mpg). Can help me,and put me in the right way to read data correctly?

// solved frist part. now i recive thath:

icy-br: 128,128 ice-audio-info: ice-samplerate=44100;ice-bitrate=128;ice-channels=2 icy-description: radio fff icy-genre: Various icy-name: RADIO icy-pub: 0 icy-url: http://url.com icy-metaint: 16000 Cache-Control: no-cache Content-Type: audio/mpeg

how to read other metadata?

Foi útil?

Solução

The metadata for SHOUTcast/Icecast streams is not in the headers, but in the actual stream itself.

That icy-metaint: 16000 header you have is the key. Every 16,000 bytes, you will get a metadata block. The first byte in that block indicates metadata length. Multiply its value by 16 to get the length in bytes. Once you do that, you will end up with something like this:

StreamTitle='Awesome Trance Mix - DI.fm';StreamUrl=''

It will be padded at the end by null bytes until you reach the length of the block.

I have answered the same question here for PHP, but the concept is the same no matter what language: Pulling Track Info From an Audio Stream Using PHP

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top