I'm trying to store in a variable the duration of a vimeo video using the API.
here is my code :
var iframe = document.querySelector('iframe');
var player = new Vimeo.Player(iframe);
var duree = player.getDuration().then(function(duration) {
// duration = the duration of the video in seconds
}).catch(function(error) {
// an error occurred
});
console.log(duree);
when I console.log my variable "duree", here is what I get :
Promise { <state>: "pending" }
the only way to get the duration in my console is to add console.log(duration);
inside my function.
like this :
var duree = player.getDuration().then(function(duration) {
console.log(duration);
}).catch(function(error) {
// an error occurred
});
console.log(duree);
I don't understand what I am doing wrong, I only want to store the duration inside my variable "duree".
can anybody help me with this ?
thanks