JSON API data for Radio Song Current Playing Information
{“server”:”http:\/\/streaming.radioforge.com\/stream”,”title”:”Today-sHottestHits”,”description”:””,”content_type”:”audio\/mpeg”,”mount_start”:””,”bit_rate”:””,”listeners”:”50″,”most_listeners”:”100″,”genre”:”various”,”url”:””,”now_playing”:{“artist”:””,”track”:””,”song”:”On Air – Today’s Hottest Hits”},”quality”:”5.00″}
MusicInformation Class
//package com.svnlabs.android; import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpPost; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.params.BasicHttpParams; import org.json.JSONObject; import android.content.Context; public class MusicInformation { private static String title; private static String artist; private static String song; private static int listeners; public static void getMusicInformation(Context context, String jsonUrls) { DefaultHttpClient httpclient = new DefaultHttpClient(new BasicHttpParams()); HttpPost httppost = new HttpPost(jsonUrls); // Depends on your web service httppost.setHeader("Content-type", "application/json"); InputStream inputStream = null; String result = null; try { HttpResponse response = httpclient.execute(httppost); HttpEntity entity = response.getEntity(); inputStream = entity.getContent(); BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"), 8); StringBuilder sb = new StringBuilder(); String line = null; while ((line = reader.readLine()) != null) { sb.append(line + "\n"); } result = sb.toString(); JSONObject generalJson = new JSONObject(result); listeners = generalJson.getInt("listeners"); JSONObject nowPlayingJson = new JSONObject(result).getJSONObject("now_playing"); title = nowPlayingJson.getString("track"); artist = nowPlayingJson.getString("artist"); song = nowPlayingJson.getString("song"); } catch (Exception e) { } finally { try { if(inputStream != null) { inputStream.close(); } } catch(Exception e){ } } } public static String getTitle(Context context) { if(title != "" || artist != null) { return title; } else { return "none"; } } public static String getSong(Context context) { if(song != "" || song != null) { return song; } else { return "none"; } } public static String getArtist(Context context) { if(artist != "" || artist != null) { return artist; } else { return "none"; } } public static int getListeners() { return listeners; } }
Fetch Metadata
/* import */ import java.io.IOException; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; /* ............. .......... */ public void RadioTitle() { // Music information stuff scheduleTaskExecutor = Executors.newScheduledThreadPool(5); // This schedules a task to run every 25 seconds scheduleTaskExecutor.scheduleAtFixedRate(new Runnable() { public void run() { // Parsing JSON MusicInformation.getMusicInformation(getApplicationContext(), "http://api4.radioforge.com/"); // JSON API URL // Needed to update stuff in UI, otherwise exception runOnUiThread(new Runnable() { @Override public void run() { // Check internet connection //checkInternetAndClose(); // Check if title changed since last check radioTitle.setText(MusicInformation.getSong(context)); } }); } }, 0, 25, TimeUnit.SECONDS); }
You can subscribe to our API get all Metadata for Icecast / Shoutcast Servers its $5 / month
ICECAST SHOUTCAST METADATA
Features:
* API provide current playing song Metadata for Icecast / Shoutcast in plain text format or JSON
* API is user key authentication based