Prev Previous Post   Next Post Next
Old 11th July 2017, 21:34   #1
ricktee76
Junior Member
 
Join Date: Sep 2015
Posts: 9
Really Simple AJAX now playing script

Super easy now playing script, contains 2 files and updates the current song every 10 seconds.

If you are using php simply include demo.php wherever you want the song to be displayed.

code:
<?php include 'demo.php'; ?>


demo.php
code:
<?php

//error_reporting(E_ERROR | E_WARNING | E_PARSE);

?>

<html><script type="text/javascript" src="http://ajax.googleapis.com/ajax/
libs/jquery/1.3.0/jquery.min.js"></script>
<script type="text/javascript">
var auto_refresh = setInterval(
function ()
{
$('#load_songs').load('playing.php').fadeIn("slow");
}, 10000); // refresh every 10000 milliseconds (10 seconds)
</script>
<body>
<div id="load_songs"><center><small> Loading Stream Please Wait.....</small></center></div>
</body>

</html>



playing.php
code:
<?php

$sc_url_ip = "6x.3x.18x.14x"; // <= CHANGE THIS TO YOUR IP
//ex: 6x.3x.18x.14x

$sc_url_port = "8000"; // <= CHANGE THIS IF NEEDED

function getNowPlaying($sc_url_ip,$sc_url_port)
{

$open = fsockopen($sc_url_ip,$sc_url_port,$errno,$errstr,'.5');
if ($open) {
fputs($open,"GET /7.html HTTP/1.1\nUser-Agent:Mozilla\n\n");
stream_set_timeout($open,'1');
$read = fread($open,200);
$text = explode(",",$read);
if($text[6] == '' || $text[6] == '</body></html>'){ $msg = ' live stream '; } else { $msg = $text[6]; }
$text = $msg;
} else { return false; }
fclose($open);

return $text;
}

//////////////////

//get the song now playing

$current_song = getNowPlaying($sc_url_ip,$sc_url_port);

//print $current_song;

//print $current_song;
$singinfo = explode(" - ",$current_song);

$artist = urlencode($singinfo[0]);
$album = urlencode(strip_tags($singinfo[1]));

?>

ricktee76 is offline   Reply With Quote
 
Go Back   Winamp & Shoutcast Forums > Shoutcast > Shoutcast Discussions

Tags
now playing, php

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump