Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Estou tentando pegar dados do SHOUTCAST, no arquivo XML que o SHOUTCAST gera com as informações...
Segue meu código:
<?php
$radiowp = array();
$xmlradiowp = array();
$error = 0;
$queryStatus = db::Assoc(db::Query("SELECT * FROM radio_dados ORDER BY id ASC LIMIT 1"));
$ipwp = $queryStatus['ip'];
$portwp = $queryStatus['port'];
$ippwp = $ipwp.":".$portwp;
$passwp = $queryStatus['senha_radio'];
// Change IP_RADIO_PORT to your <myradioip>:<port> and RADIO_PASS to your <adminpass>
define($ipwp.":".$portwp, $ipwp.":".$portwp);
define($passwp, 'xxxxx');
// Url of admin area in shoutcast
$file = 'http://'.$ippwp.'/admin.cgi?user=admin&pass='.$passwp.'&mode=viewxml&sid=1';
// Retrieving shoutcast radiowp
if(!$xml = simplexml_load_file($file))
{
// If something goes wrong, keep the error message
$error = 1;
$radiowp['message'] = 'Ops, o servidor caiu! Rapidinho consertamos, volte em breve!';
}
// If nothing went wrong...
if($error < 1)
{
// Convert xml to array
$xmlradiowp = xml2array($xml);
// Uncomment to see all information retrieved
// print('<pre>'); print_r($xmlradiowp); die;
// Check if server is up
if($xmlradiowp['STREAMSTATUS'] == 1)
{
$radiowp['locutor'] = $xmlradiowp['SERVERTITLE']; // Radio Title
$radiowp['radiourl'] = $xmlradiowp['SERVERURL']; // Radio Url
$radiowp['radiogenre'] = $xmlradiowp['SERVERGENRE']; // Radio Genre
$radiowp['nowplaying'] = $xmlradiowp['SONGTITLE']; // Now playing
$radiowp['nextsong'] = $xmlradiowp['NEXTTITLE']; // Next song in queue
$radiowp['listeners'] = $xmlradiowp['UNIQUELISTENERS']; // How many is listening right now
$radiowp['songhistory'] = $xmlradiowp['SONGHISTORY']['SONG']; // Song history
}
else
{
// If server is down, keep the error message
$error = 1;
$radiowp['message'] = 'Ops, o servidor caiu! Rapidinho consertamos, volte em breve!';
}
}
/**
* [http://www.php.net/manual/en/ref.simplexml.php#111227](http://www.php.net/manual/en/ref.simplexml.php#111227)
* @param unknown $xmlObject
* @param unknown $out
* @return unknown
*/
function xml2array ( $xmlObject, $out = array () )
{
foreach ( (array) $xmlObject as $index => $node )
$out[$index] = ( is_object ( $node ) || is_array ( $node ) ) ? xml2array ( $node ) : $node;
return $out;
}
?>Posta a mensagem inteira
Warning: simplexml_load_file(site) [function.simplexml-load-file]: failed to open stream: Connection refused in/home/jorna150/public_html/lib/radio.php on line 19
Warning: simplexml_load_file() [function.simplexml-load-file]: I/O warning : failed to load external entity "site" in /home/jorna150/public_html/lib/radio.php on line 19
OBS : aonde eu coloquei site, vai o link, e o link é correto... já atestei
Vê se isto ajuda.
Tenta substituir por
$file = file_get_contents('site');
$xml = simplexml_load_string($file);Resolveu... Mas agora descobri o erro... O SHOUTCAST ou STREAMING, não está permitindo que eu requesite essas informações por código, só consigo por iframe...
Eu requisitei outras páginas com o CURL, e deu certo, porém no CHOUTCAST não..
Tentei também por Jquery, Ajax, mas nada funciona, diz que não está autorizado a acessar o site... Saberiam de alguma configuração que eu deva fazer no SHOUTCAST?
OBRIGADO!
E ? Qual a dúvida ?