I am working with StreamOn, a streaming audio provider to distribute my audio stream for an online radio station. They make current “now playing” song information available on their servers (they provide me with the URL containing this information). Here is the data that is displayed when I go to that URL:
{
"interval": {
"id": 0,
"starts_at": 1306738563270,
"ends_at": 1306738735270
},
"identifier": "Music-FS680",
"category": "music",
"original_category": "Music",
"buy_link": "",
"title": "I'm That Kind of Girl",
"artist": "Patty Loveless",
"album": "On Down the Line",
"publisher": "UMG Recordings, Inc.",
"itunes_song_id": "1290089",
"album_art": {
"src": "http://www.streamon.fm/player/getAlbumArt.php?u=http://a6.mzstatic.com/us/r1000/016/Features/20/41/7b/dj.twfxwryv.170x170-75.jpg",
"width": 170,
"height": 170,
"alt": "On Down the Line",
"link": ""
},
"next_song": "Little Bitty by Alan Jackson",
"next_buy_link": "",
"next_album_art": {
"src": "http://www.streamon.fm/player/getAlbumArt.php?u=http://a5.mzstatic.com/us/r1000/025/Features/b5/cb/0b/dj.frlbluta.170x170-75.jpg",
"width": 170,
"height": 170,
"alt": "Everything I Love",
"link": ""
},
"banner": {
"src": "",
"width": 0,
"height": 0,
"alt": "",
"link": ""
}
}
I need to take that dynamic data, and cleanly display it on my homepage so that it looks like this:
Title: I'm That Kind of Girl
Artist: Parry Loveless
Album: On Down the Line
I know this is text parsing, but I can’t seem to figure out what type of text parsing method I need to use.
That’s JSON. Various parsers for different languages are available at http://json.org/
GoDaddy supports PHP as server-side language. A quick-and-dirty way to get parse the JSON response from an external server. Save the below code with a
.phpextension (likecurrently_playing.php):Usually, you would do some caching of the result, updating the song information every 10 seconds should be fine.
It appears that the response contains data on the end time of the song (in milliseconds). A better approach would then be checking if this time has passed, and if so, update the cache.
To embed it in a HTML page, use: