【发布时间】:2012-02-04 00:02:24
【问题描述】:
我正在为我的网站上的直播者建立一个网页。
但是我遇到了一些问题,我已经创建了一个表格,并且我一直在搞砸它并且我已经取得了很好的结果,但它还不完美,所以我仍然被卡住了
当前示例http://brokendiamond.org/?q=node/9 ;
我遇到了 2 个问题; 1 我的页面在大约 2 - 3 秒内加载,这仍然有点太长了 2 我的表中的数据也没有像预期的那样更新,当我的流上线时,它没有显示在我的表中,即使 xml 文件确实得到了更新,也没有正确显示视图计数,所以这有问题,
对此问题的任何意见或帮助将不胜感激,因为我真的很想完成这部分,所以我可以继续我的待办事项列表。
我听说过人们谈论现金,但我不知道如何做到这一点,所以这可能是一个方向。
XML API 可以在以下位置找到: http://api.own3d.tv/liveCheck.php?live_id=210230
我网页的当前代码是:
Hello and welcome to the Livestream page for the broken diamond community here you can find all our content creator's livestream pages to watch them game. you can chat with other members and even them! We always welcome new followers and will love to hear about suggestions for games, in game tips and all those opinions we know you have to share! Enjoy your favorite streamers, and don't forget their schedule can be found under the information block in the menu.
<div id="livetable">
</div>
<script type="text/javascript">
load();
var intervalID;
refresh();
function refresh()
{
intervalID = setInterval(load, 60000);
}
function load()
{
var elem = document.getElementById("livetable");
elem.innerHTML = '<?php loadpage() ?><br>';
}
</script>
<?php
define('ELEMENT_CONTENT_ONLY', true);
define('ELEMENT_PRESERVE_TAGS', false);
function value_in($element_name, $xml, $content_only = true)
{
if ($xml == false)
{
return false;
}
$found = preg_match('#<'.$element_name.'(?:\s+[^>]+)?>(.*?)'.'</'.$element_name.'>#s', $xml, $matches);
if ($found != false)
{
if ($content_only)
{
return $matches[1]; //ignore the enclosing tags
}
else
{
return $matches[0]; //return the full pattern match
}
}
// No match found: return false.
return false;
}
function loadpage()
{
echo "<table cellpadding=\"0\" cellspacing=\"0\" style=\"width: 95%\" >";
echo "<tr class=\"info-row\" bgcolor=#252525 style=\"color:white; height: 15px;\">";
echo "<td style=\"width: 14%; height: 10px; padding-left: 5px;\"><b>Preview</b></td>";
echo "<td style=\"width: 10%; height: 10px; padding-left: 5px;\"><b>Live</b></td>";
echo "<td style=\"width: 36%; height: 10px; padding-left: 5px;\"><b>Stream</b></td>";
echo "<td style=\"width: 10%; height: 10px; padding-left: 5px;\"><b>Viewers</b></td>";
echo "<td style=\"width: 10%; height: 10px; padding-left: 5px;\"><b>Time online</b></td>";
echo "</tr>";
addrow(107473,10,"Osuryn","Osuryn is streaming random games live",false);
addrow(210320,28,"Dennojj","Dennojj is streaming PS3 games",true);
echo "</table>";
}
function addrow($streamID, $streamPage , $streamName , $streamSlogan, $odd)
{
if ($odd)
{
echo "<tr class=\"content-row online\" id=\"958\" bgcolor=#A7A7A7>";
}
else
{
echo "<tr class=\"content-row online\" id=\"958\" bgcolor=#BFBFBF>";
}
echo "<td style=\"width: 14%;\"><img src=\"http://img.hw.own3d.tv/live/live_tn_".$streamID."_.jpg\" style=\"height: 72px;\" \></td>";
echo "<td style=\"width: 10%; padding-left: 5px;\"><br><br><b>".getLiveStatus($streamID)."</b></td>";
echo "<td style=\"width: 36%; vertical-align: top; padding-top: 6px; padding-right: 6px;\">";
echo "<div><br><a href=\"http://brokendiamond.org/?q=node/$streamPage\">$streamName</a></div>";
echo "<div style=\"padding-top: 6px; font-size: 11px;\">$streamSlogan</div>";
echo "</td>";
echo "<td style=\"width: 10%; padding-left: 5px;\"><br><br>".getLiveViews($streamID)."</td>";
echo "<td style=\"width: 10%; padding-left: 5px;\"><br><br>".getOnTime($streamID)." minutes online</td>";
echo "</tr>";
}
function getLiveStatus($streamID)
{
$request = 'http://api.own3d.tv/liveCheck.php?live_id='.$streamID;
$arg = '240';
$session = curl_init($request.$arg);
curl_setopt($session, CURLOPT_HEADER, false);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($session);
curl_close($session);
if (preg_match("/true/",$response, $result))
{
$streamStatus="Live";
}
else
{
$streamStatus="Offline";
}
return $streamStatus;
}
function getLiveViews($StreamID)
{
$request = 'http://api.own3d.tv/liveCheck.php?live_id='.$StreamID;
$arg = '240';
$session = curl_init($request.$arg);
curl_setopt($session, CURLOPT_HEADER, false);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($session);
curl_close($session);
$viewStatus =value_in('liveViewers', $response) + "";
return $viewStatus;
}
function getOnTime($StreamID)
{
$request = 'http://api.own3d.tv/liveCheck.php?live_id='.$StreamID;
$arg = '240';
$session = curl_init($request.$arg);
curl_setopt($session, CURLOPT_HEADER, false);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($session);
curl_close($session);
$onStatus =value_in('LiveDuration', $response) + "";
return $onStatus;
}
?>
【问题讨论】:
标签: php javascript html live-streaming