Old 11th July 2017, 21:34   #1
ricktee76
Junior Member
 
Join Date: Sep 2015
Posts: 11
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
Old 14th July 2017, 08:02   #2
dopelabs
Senior Member
 
dopelabs's Avatar
 
Join Date: Oct 2006
Location: Silicon Valley
Posts: 493
Send a message via AIM to dopelabs
I wouldn't call this an 'AJAX' script... I would call this a PHP script. since its PHP thats actually doing all the work here. this also requires the web host to support sockets in their PHP configuration, most shared hosting providers don't. the only thing you are using Ajax for is calling the php script and displaying it within a div.... AJAX will also not load cross domain or cross port, you need to use something like jsonp.

if you have a V2 DNAS
code:

<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
</head>
<body>
<script>
$.ajax({
url : "http://IP:PORT/statistics?json=1",
dataType: 'JSONP',
type : "GET",
success:function(data){
console.log(data);
}
});
</script>
</body>
</html>

dopelabs is offline   Reply With Quote
Reply
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