(using https://github.com/vimeo/player.js/)
I have 4 Vimeo embedded videos on a page and a button (next) to move to the next page. I would like to allow the user to move to the next page only after they have viewed all 4 videos.
I start by collecting all videos:
var iframes = $( 'iframe.video' );
Then I loop through them to use the vimeo api and check if they were played:
var videos = [];
var videos_flags = [];
for( var i = 0 ; i < iframes.length ; i++ ) {
videos[i] = new Vimeo.Player( iframes[i] );
videos[i].on('play', function( data ) {
videos_flags[i] = true;
} );
}
Eventually, if I do console.log( videos_flags )
I get 3 empty and 1 true no matter how many videos I have played.
$( '.next' ).on( 'click', function() {
console.log( videos_flags );
} );
What am I doing wrong?
Thanks!