user492642
user492642

Reputation: 169

get current duration facebook video api

I have some problems with getting current duration , it call the function only one time instead of calling every 10 seconds

$.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'));

});

My function setTimeout seems to be correct , I don't know how can i fix my problem

Upvotes: 1

Views: 399

Answers (1)

Yosvel Quintero
Yosvel Quintero

Reputation: 19090

Instead of using setTimeout() you have to use setInterval() to repeatedly call a function or execute a code snippet, with a fixed time delay between each call:

setInterval(fn, miliseconds);

Upvotes: 1

Related Questions