Reputation: 505
I embedded a protected vimeo video on a site. Is there a method via the JavaScript API to find out if a password is currently being requested?
Upvotes: 0
Views: 95
Reputation: 505
At the moment there seems to be no other option than to listen to an error message. So unfortunately there is nothing else to do than keep trying to play the video and see if an error is thrown. Unfortunately not that very nice.
//check if video is playing
player.getPaused().then(function(paused) {
//try to pause video
player.pause().then(function() {
//when video was already playing, play again
if(!paused) player.play()
}).catch(function(error) {
//when video couldn't pause and the error is 'PasswordError'
if(error.name == 'PasswordError') {
//currently vimeo asks for password
videoWrp.classList.remove('loading');
videoWrp.classList.add("pw-protection");
//loop over the play function, till password was entered
pwLoop = setInterval(function (){
player.play().then(function() {
//password was entered
videoWrp.classList.remove("pw-protection");
clearInterval(pwLoop);
})
}, 500);
}
});
});
Upvotes: 0