Reading shoutcast stream on Android

In this post I will be writing about how to extract meta-data info from Shoutcast url.
The reason for writing this post is that not much info is available about this stuff on Android, thus without wasting any more time, lets begin.

The first step in this procedure is to call the url, with Icy-MetaData = 1, as it’s header.
So the code will become some thing like this:

//=== Fetch ICY INT
URL url = new URL(rurl);
URLConnection conn = url.openConnection();
conn.addRequestProperty("Icy-MetaData", "1");

When you call the url with this header, you will receive a header in response, icy-metaint. This field indicates after how many bytes we have the meta-data, so we will have to skip these many bytes.

int discard = Integer.parseInt(hList.get(META_INT).get(0) + "");
InputStream is = conn.getInputStream();
long read = 0;
long skipped = is.skip(discard);
while (skipped != discard) {
skipped += is.skip(discard - skipped);

Its time to read the chunks of meta-data , the first byte *16 of this chunk represents the number of bytes that contain the data, rest are just padded.

//=== Read 1st byte
int fb =;
//=== Read metadata, first byte *16
int mdl = fb * 16;
read = 0;
String md = "";
do {
byte[] mdb = new byte[mdl - (int) read];
read =;
md += new String(mdb, 0, mdb.length);
} while (read != mdl);

So we have our meta data now, time to parse it.
The data is separated by ‘;’ so we just have to split now.

String metdata = new String(md.trim().getBytes(), "utf-8");
//=== Extract
String[] data = metdata.split(";");
Tag t = new Tag();
for (String tag:data){

So the final code looks like this:

Hope you liked this post.

Leave a Reply