PHP script to extract artist & title from Shoutcast/Icecast stream

帅比萌擦擦* 提交于 2019-11-30 07:23:45

You will need to constantly query the stream at a set interval to find when the song changes.

This can be best done by scheduling a cron job. If on Windows, you should use the Windows Task Scheduler

TheUnknownGeek

If you want to run the PHP script to keep your meta data up to date (I'm assuming you're making a website and using html audio tags here) you can use the ontimeupdate event with an ajax function. If you're not you probably should look up your audio playback documentation for something similar.

<audio src="http://ip:port/;" ontimeupdate="loadXMLDoc()">

You can find a great example here http://www.w3schools.com/php/php_ajax_php.asp

You want to use the PHP echo function all the relevant information at once using one php variable at the very end of your script.

<?php ....
$phpVar=$streamtitle;
$phpVar2=$streamsong;
$result="I want my string to look like this: <br> {$phpVar} {$phpVar2}";
echo $result;
?>

and then use the function called by the .onreadystatechange to modify the particular elements you want on your website by using the .resonseText (this will contain the same content as your PHP script's echo).

After SCOURING the web for 4 hours, this is the only Shoutcast metadata script I've found that works! Thankyou.

To run this constantly, why not use a setInterval combined with jQuery's AJAX call?

<script>
$(function() {
    setInterval(getTrackName,16000);
});

function getTrackName() {
    $.ajax({
    url: "track_name.php"
    })
    .done(function( data ) {
    $( "#results" ).text( data );
    });
}
</script>

Also your last couple 'echo' lines were breaking the script for me. Just put quotes around the Meta Interval, etc....

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!