Youtube API event on a specified time

后端 未结 3 1089
耶瑟儿~
耶瑟儿~ 2020-12-29 10:01

Is it possible through the YouTube API to fire an event when the video reaches a specified time? e.g. when the video reaches 20 sec. fire the event.

Thanks,
Maur

3条回答
  •  粉色の甜心
    2020-12-29 10:33

    Not sure if anyone agrees here but I might prefer to use setTimeout() over setInterval() as it avoids using event listeners, eg:

    function checkTime(){
        setTimeout(function(){
            videotime = getVideoTime();
            if(videotime !== requiredTime) {
                 checkTime();//Recursive call.
            }else{
                //run stuff you want to at a particular time.
                //do not call checkTime() again.
            }
        },100);
    }
    

    Its a basic pseudocode but hopefully conveys the idea.

提交回复
热议问题