Hieronder vind je een Icecast Now Playing script opgemaakt in PHP, wat werkt met Icecast v2. Met dit Icecast PHP script kun je de huidige titel en artiest weergeven op je website. Voorbeeld: nowplaying-icecast.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
<?php function getMp3StreamTitle($streamingUrl, $interval, $offset = 0, $headers = true) { $needle = 'StreamTitle='; $ua = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.110 Safari/537.36'; $opts = array('http' => array( 'method' => 'GET', 'header' => 'Icy-MetaData: 1', 'user_agent' => $ua ) ); if (($headers = get_headers($streamingUrl))) foreach ($headers as $h){ $currentSection = explode(':', $h); if (strpos(strtolower($h), 'icy-metaint') !== false && ($interval = $currentSection[1])) break; } $context = stream_context_create($opts); if ($stream = fopen($streamingUrl, 'r', false, $context)) { $buffer = stream_get_contents($stream, $interval, $offset); fclose($stream); if (strpos($buffer, $needle) !== false) { $currentSectionTwo = explode($needle, $buffer); $title = $currentSectionTwo[1]; return substr($title, 1, strpos($title, ';') - 2); } else return getMp3StreamTitle($streamingUrl, $interval, $offset + $interval, false); } else throw new Exception("Unable to open stream [{$streamingUrl}]"); } $nowplaying= (getMp3StreamTitle('http://intenseradio.live-streams.nl:8000', 19200)); echo "$nowplaying"; ?> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
<?php function getMp3StreamTitle($streamingUrl, $interval, $offset = 0, $headers = true) { $needle = 'StreamTitle='; $ua = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.110 Safari/537.36'; $opts = array('http' => array( 'method' => 'GET', 'header' => 'Icy-MetaData: 1', 'user_agent' => $ua ) ); if (($headers = get_headers($streamingUrl))) foreach ($headers as $h){ $currentSection = explode(':', $h); if (strpos(strtolower($h), 'icy-metaint') !== false && ($interval = $currentSection[1])) break; } $context = stream_context_create($opts); if ($stream = fopen($streamingUrl, 'r', false, $context)) { $buffer = stream_get_contents($stream, $interval, $offset); fclose($stream); if (strpos($buffer, $needle) !== false) { $currentSectionTwo = explode($needle, $buffer); $title = $currentSectionTwo[1]; return substr($title, 1, strpos($title, ';') - 2); } else return getMp3StreamTitle($streamingUrl, $interval, $offset + $interval, false); } else throw new Exception("Unable to open stream [{$streamingUrl}]"); } $nowplaying= (getMp3StreamTitle('http://intenseradio.live-streams.nl:8000', 19200)); echo "$nowplaying"; ?> |