0

我有一个 youtube 视频,它的持续时间以秒为单位,我想为该视频设置一个计时器,一旦完成,然后调用一个具有不同视频的函数。到目前为止,我所拥有的是:

$ytvidid = 'qasCLgrauAg';
$ytdataurl = "http://gdata.youtube.com/feeds/api/videos/". $ytvidid;
$feedURL = $ytdataurl;
$sxml = simplexml_load_file($feedURL);
$media = $sxml->children('http://search.yahoo.com/mrss/');
// get <yt:duration> node for video length
$yt = $media->children('http://gdata.youtube.com/schemas/2007');
$attrs = $yt->duration->attributes();
$length = $attrs['seconds'];

在此示例中返回 16 秒,所以我尝试过:

usleep($length * 1000000);
flush();
loadnext();

function loadnext(){
    //heres my next video
}

出于某种原因,这不起作用..我做错了什么吗?我也尝试过 javascript window.setInterval(...) 但这在下一个视频加载时重置间隔也不起作用。任何帮助深表感谢 :)

4

3 回答 3

1

对于16 seconds延迟,您必须使用

usleep($length * 1000000);  // 1000000 == 1 second
于 2012-12-31T06:17:34.273 回答
0

由于您处理的是秒(而不是微秒),因此您可以考虑使用sleep而不是usleep.

于 2012-12-31T06:21:19.537 回答
0

好的,经过几个小时的阅读,我发现我想要完成的事情不能用 php 的 sleep 或 usleep 函数来完成。所以我终于让它与 javascript 一起工作:

<script type="text/javascript">
var id = 1;
next(id);
var t;
function setValue(time, rowid)
{

    id = rowid;
    t = setInterval(cleartime, time * 1000);    
}

function cleartime()
{
    clearInterval(t);
    next(parseInt(id, 10));
}
function next(id){
    //this gets values and calls the setValue function again        
}
</script>
于 2013-01-05T23:45:52.853 回答