Problem
I have multiple Vimeo embeds on one page. They each have custom, separate html Play/Pause buttons for controlling them.
I assumed that the best way to do this would be to create an array of players and go from there, using a bit of jQuery. Like so:
vimeoPlayers = [];
// Set up the players
$('.js-vid-player').each(function(){
iframe = $(this).find('iframe');
videoId = iframe.attr('id');
vimeoPlayers[videoId] = new Vimeo.Player(iframe);
});
// Handle the play buttons
$('.js-vid-play').click(function(){
videoId = $(this).attr('data-video'); // Get the appropriate video we want to control.
vimeoPlayers[videoId].play(); // This works fine.
$(vimeoPlayers).each(function() {
// Ideally, I would like to pause all other videos here somehow, but I'm doing something wrong.
});
});
Questions:
- First, is this the correct way of doing this? Having the multiple players in an array? The Vimeo documentation doesn't seem to give any examples of handling multiple players... or else I completely missed it somehow.
- Second, how to I control all the players at once? For example, my comment in the code above about stopping all other players.
Thanks in advance!