0

I'm working on a front end for an internet radio station and they're broadcasting a SHOUTcast stream. I already have the audio, I just need a simple and reliable way to display the metadata on the page. I'm using a MEAN stack to run the whole thing so if anyone has an answer that fits into that framework that would be preferable.

gvlasov
  • 18,638
  • 21
  • 74
  • 110
manmon42
  • 319
  • 3
  • 14
  • Please share your code and explain what you've already tried. – BenM Jul 17 '15 at 22:36
  • I have an API that can look up your metadata for your stream. It isn't available at the moment, but if you e-mail me at brad@audiopump.co, I will contact you when it is. In the MEAN time (ha, a joke, yeah!?), see this post: http://stackoverflow.com/a/4914538/362536 It's for PHP, but the concept for any language is identical. Bottom line is, you need your server to connect to the SHOUTcast server, get the metadata, and return it to your front end. – Brad Jul 17 '15 at 22:38
  • I tried `$http.get('http://s2.radioboss.fm:8024/currentsong?sid=1').success(function(currentSong) { console.log(currentSong); $scope.currentSong = currentSong; });` but that just returned `XMLHttpRequest cannot load http://s2.radioboss.fm:8024/currentsong?sid=1. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:9000' is therefore not allowed access.` – manmon42 Jul 17 '15 at 22:39
  • Thanks, so now I've got the info on my server, any recommendations about how to get the data to the front end? I already can set up a REST api but that would have to be called every time the track changes, and it would have to know when the track changes. – manmon42 Jul 18 '15 at 03:04

1 Answers1

2

Here's a little something I whipped up. It uses json-p results from shoutcast, so can be done client side without any CORS issues etc

function doSomething(obj) {
    document.getElementById('shout').textContent = obj.songtitle;
}

var getShout = (function() {
    var script;

    return function shout(fn, sc, sid) {
        if (script) {
            document.body.removeChild(script);
        }
        script = document.createElement('script');
        script.src = sc + 'stats?json=1&callback=' + fn + '&sid=' + sid + '&rand=' + Math.random();
        document.body.appendChild(script);
    };
}());

document.getElementById('eatme').addEventListener('click', function() {
    getShout('doSomething', 'http://s2.radioboss.fm:8024/', 1)
});
<input id="eatme" type="button" value="press me" />
<div id="shout"></div>
Jaromanda X
  • 53,868
  • 5
  • 73
  • 87
  • This seems like a good solution, but it would need to be run every time the song switched, which it doesn't seem to be able to know. Or it would have to be regularly polled. Either way this seems trickey. – manmon42 Jul 18 '15 at 05:17
  • yeah, not sure how any solution external to DNAS would actually know when the song changes without polling – Jaromanda X Jul 18 '15 at 05:36