Advertisement
FuzzyMannerz

Icecast Now Playing Javascript Fallback Modification

Mar 30th, 2015
862
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Original - http://linge-ma.ws/update-listeners-track-on-a-website-using-icecast-jsonp-and-jquery/
  2. // Modified by Fuzzy Mannerz to include fallback autoDJ stream.
  3. function radioTitle() {
  4.  
  5. // This is the URL of the json.xml file located on your radio server.
  6.     var url = 'YOUR-RADIO-SERVER-IP:PORT/json.xsl';
  7.  
  8. $.ajax({
  9.    type: 'GET',
  10.     url: url,
  11.     async: true,
  12.     jsonpCallback: 'parseMusic',
  13.     contentType: "application/json",
  14.     dataType: 'jsonp',
  15.     success: function(json) {
  16.         // These are the elements we're updating that will hold the track title.
  17.     // Change "/LiveStreamMountPoint" and "/FallbackStreamMountPoint" accordingly.
  18. $('#track-title').text(json['/LiveStreamMountPoint']['title']);
  19. if ($('#track-title').is(':empty')){
  20. $('#track-title').text(json['/FallbackStreamMountPoint']['title']);
  21. }    
  22.     },
  23.     error: function(e) {
  24.        console.log(e.message);
  25.     }
  26. });
  27.  
  28. }
  29.  
  30. $(document).ready(function(){
  31.  
  32.   setTimeout(function(){radioTitle();}, 2000);
  33.   setInterval(function(){radioTitle();}, 15000); // We're going to update our html elements / player every 15 seconds
  34.  
  35. });
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement