Seite 1 von 1
Iframe nach update reloaden
Verfasst: Do 23.Jul, 2009 20:37
von MADxHAWK
Hallo zusammen,
hab gerade ein kleines Problem.
Momentan habe ich in meinem phpbb3 in einem iframe ein phpscript eingebunden das alle 30sek. per reload neu aufgerufen wird, einen Shoutcastserver abfragt und ggf. den Songtitel, den ich mit einem Javaticker anzeige, aktualisiert. Dabei wird natürlich auch der Javaticker ständig neu geladen um den neuen Songtitel zu übernehmen, da sich der html code zum einbinden des Tickers mit in der phpdatei befindet.
Ist es irgendwie möglich mit der php den shoutcast alle x sek abzufragen und den Ticker im iframe nur neu zu laden wenn a.) ein neuer Titel läuft oder b.) der Shoutcast offline geht.
Die Erkennung Shoutcast on/offline und neuer Titel ist hier nicht das Problem sondern den iframe zu aktualisieren.
Gruss
MAD
Verfasst: Fr 24.Jul, 2009 21:43
von oxpus
Hast du hierbei schon mal über AJAX nachgedacht?
Verfasst: Do 30.Jul, 2009 15:42
von MADxHAWK
Hallo,
sorry das ich erst jetzt antworte, kam die letzten tage nicht dazu. Ja habe ich schon drüber nachgedacht, habe aber keinerlei ahnung von ajax und bisher auch nichts gefunden was mir weiterhilft.
Gruss
Mad
Verfasst: Do 30.Jul, 2009 18:01
von oxpus
Wäre ja auch nur ein Vorschlag.
Da ich allerdings dein iframe nicht kenne, kann ich da auch weniger konkret helfen...
Verfasst: Do 30.Jul, 2009 18:22
von MADxHAWK
Hi, hier mal die codes
iframe:
Code: Alles auswählen
<table class="tablebg" cellspacing="1" width="100%">
</tr>
<tr class="row1">
<td align="center">
<iframe src="./Vledticker/index.html" width="100%" height="20" scrolling="No" marginheight="0" marginwidth="0" frameborder="0"></iframe>
</td>
</tr>
</table>
index.html:
Code: Alles auswählen
<HTML>
<HEAD>
<meta http-equiv="expires" content="0">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="pragma" content="no-cache" />
</HEAD>
<BODY BGCOLOR="#000000">
<center>
<applet code=Vledticker.class width=500 height=20>
<param name=TextFile value="stream.txt">
<param name=ColorBack value=000000>
<param name=ColorLedOff value=444444>
<param name=ColorLeft value=FF0000>
<param name=ColorCenter value=00ff00>
<param name=ColorRight value=0000ff>
<param name=DotSpace value=1>
<param name=DotStep value=1>
<param name=TicksPerSec value=40>
</applet>
</center>
</BODY>
</HTML>
und die stream.php
Code: Alles auswählen
$stream = fsockopen("<streamurl>", <port>);
$admin_pass = "***********";
if (!$stream) {
//echo "$errstr ($errno)<br />\n";
} else {
fputs ($stream, "Get /admin.cgi?pass=$admin_pass&mode=viewxml&page=0 HTTP/1.0\r\nUser-Agent: XML Getter (Mozilla Compatible)\r\n\r\n");
while (!feof($stream)) {
$stream_data .= fgets($stream,128);
}
fclose($stream);
}
preg_match('%<(STREAMSTATUS)[^>]*>(.*?)</\1>%', $stream_data, $streamstatus);
preg_match('%<(SONGTITLE)[^>]*>(.*?)</\1>%', $stream_data, $currentsong);
$currentsong = str_replace('_', ' ', $currentsong[2]);
$currentsong = str_replace('-', '/', $currentsong);
$currentsong = str_replace("`", "'", $currentsong);
if($_GET['t'] != md5($currentsong) || $_GET['s'] != $streamstatus[2])
{
// iframe neu laden damit neuer text aus stream.txt vom applet (index.html) übernommen wird
}
if ($streamstatus[2] == "1")
{
$now_playing = '-MLN0W0ML-FFCC33-Ihr hört ' . $currentsong . ' ';
$refresh = '<meta http-equiv="refresh" content="30; URL=./stream.php?t=' . md5($currentsong) . '&s=' . $streamstatus[2] . '">';
}
else
{
$now_playing = '-LLN0W1ML-FFCC33-Stream ist offline' . "\n";
$refresh = '<meta http-equiv="refresh" content="60; URL=./stream.php?t=' . md5($currentsong) . '&s=' . $streamstatus[2] . '">';
}
$file = fopen("stream.txt","w");
fwrite($file, $now_playing);
fclose($file);
?>
<HTML>
<HEAD>
<meta http-equiv="expires" content="0">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="pragma" content="no-cache" />
<?php echo $refresh; ?>
</HEAD>
<BODY BGCOLOR="#ffffff" <?php echo $onload; ?>>
</BODY>
</HTML>
Gruss
Martin
Verfasst: Do 30.Jul, 2009 18:47
von oxpus
... und Zeit müsste ich jetzt auch noch haben ...
Verfasst: Do 30.Jul, 2009 19:03
von MADxHAWK
Hi Oxpus,
danke dir erstmal und werde mal weiter basteln. Wenn du mal Zeit hast und eine Lösung wäre ich dir dankbar wenn du sie mir verrätst.
Gruss
Martin
Verfasst: So 23.Aug, 2009 00:47
von KeineAhnung
Man könnte ja auch ein Bild laden, also das Bild wird von einem PHP script erstellt und ist 1*1 groß wenn es nichts neues gibt und 2*2 wenns was neues gibt, dieses Bild dann alle 10 Sekunden via settimeout über javascript laden und gucken wie groß es ist, und wenn es halt 2*2 ist den Frame neu laden.
Pseudo PHP Code
if(neuesimStream()) {
echo '2x2Bild';
} else {
echo '1x1Bild';
}
Pseudo JS Code
function checkforNeues() {
var bild = new Image();
bild.src = 'phpCodeDerNachUpdatesGuckt.php?random=' + Math.random(); // math random gegen cachen des Browsers
if(bild.width == 2) {
//update frame
}
window.setTimeout("checkforNeues()", 10000);
}
window.setTimeout("checkforNeues()", 10000);