Title of current icecast streamed song

允我心安 提交于 2019-12-20 05:49:25

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/14540380/title-of-current-icecast-streamed-song

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