我在获取当前持续时间时遇到一些问题,它只调用一次该函数而不是每10秒调用一次
$.get('/playlistVideos', function(data){
var i = 0;
var maxDuration = 100;
var id_video;
video = JSON.parse(data);
nb_video = video.length;
$('.fb-video').attr('data-href', video[i].link);
window.fbAsyncInit = function() {
FB.init({
appId : 'XXXXXX',
xfbml : true,
version : 'v2.5'
});
// Get Embedded Video Player API Instance
FB.Event.subscribe('xfbml.ready', function(msg) {
var my_video_player = msg.instance;
my_video_player.play();
var test = my_video_player.subscribe('startedPlaying', function(e) {
window.setTimeout( function () {
console.log('duration >> '+my_video_player.getCurrentPosition());
},
10000 //check every 30 seconds
)
});
});
};
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
});
我的函数setTimeout似乎是正确的,我不知道如何解决我的问题
答案 0 :(得分:1)
而不是使用setTimeout()您必须使用setInterval()重复调用函数或执行代码段,每次调用之间有固定的时间延迟:
setInterval(fn, miliseconds);