开发者

iPhone extracting songname from the icecast streaming radio

开发者 https://www.devze.com 2023-02-06 03:27 出处:网络
I am looking to extract the Song name from an ice cast streaming radio.I 开发者_如何学运维am getting the icy-genre,icy-name n stuff. but not the song name. Can we extract it from the stream?From your

I am looking to extract the Song name from an ice cast streaming radio. I 开发者_如何学运维am getting the icy-genre,icy-name n stuff. but not the song name. Can we extract it from the stream?


From your question I presume you already added Icy-Metadata: 1 to you request.

You'll have to read the "icy-metaint" response header, that will tell you how bytes to read between each metadata update in the stream.

The following is pseudocode:

byteinterval = int(response.getHeader("icy-metaint"))
stream = response.getBodyStream()
stream.read(byteinterval)
metadata_len = byte(stream.read(1)) * 16
metadata = stream.read(metadata_len)

The metadata will look something like this:

StreamTitle='Some Song Name Stream Client Sent';StreamUrl='http://someurl.com/';

Unfortunately there's no absolute standard for either encoding of the complete metadata buffer, or the contents of the StreamTitle.

Song name may or may not contain album name, artist name and complete song name or other fields.

The metadata buffer itself may or may not be UTF-8. It's up to the streaming client to decide on what to inject. Most decent clients will use UTF-8 when forced to send non ASCII data, but not all (and they may send some native encoding like Windows-1521 or UTF-16).

If you want to keep getting metadata updates you can simply consume blocks of "byteinterval" length of bytes to get more metadata updates, or disconnect and poll the stream later.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号