1

i have a youtube video which I get its duration in seconds, I want to set a timer for that video and once it's done then call a function which has a different video. So far what i have is this:

$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'];

that returns in this example 16 seconds, so i've tried:

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

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

for some reason this doesn't work..am i doing something wrong? I've also tried javascript window.setInterval(...) but that doesn't work either in reseting the interval when the next video loads. Any help is much appreciated :)

3 Answers 3

2

for 16 seconds delay you have to use

usleep($length * 1000000);  // 1000000 == 1 second
Sign up to request clarification or add additional context in comments.

1 Comment

thanks changed it, yet instead of waiting the 16 seconds to call that function it calls it immediatly..
1

Since you're dealing in seconds (not microseconds), you might consider using sleep instead of usleep.

Comments

1

Ok after several hours of reading I figured out what I wanted to accomplish could not be done with php's sleep or usleep functions.. So I finally got it working with 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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.