Forums / API
pause videos when someone switch tab
Forums
Forum Rules
-
Be nice
Even if you disagree with someone, keep it civil.
-
Stay on topic
If it’s not relevant, leave it out or start a new thread.
-
Don't Spam
Re-re-re-re-posts drive us crazy.
-
Respect the Staff
We were members once, just like you.
Our Support Team
-
Sam
-
Mark
-
Ian
-
Tommy
-
Alex
We're here to help you 9AM-6PM EST, Monday to Friday.
Benoit Delaunay
Hey guys,
I'm working on my website but I'm usually more into graphics stuff than coding. I created tabs using javascript so all the website is on a single html page.
Now I am trying to pause all the videos when someone switch to another tab. Do you think there is a way ? Using javascript, css, html, json, moogaloop, anything.
I have a function for tab-switching but I don't know what to add in there. Probably something like "collect all the videos in the html page, pause" ? As I am fairly new to javascript I have no idea how to code this.
If someone could point me in the right direction I would be super-happy !
I would like to stick to the universal player and not flash if possible.
Ben
Pablo Bollansée
I'm looking for the same kind of functionality. The 'collect all the videos in the html page' can be done with: $$('iframe') I think, but I'm also stuck at the 'pause' part.
Did you find a solution yet ?
Benoit Delaunay
Hi, I'm working on it, I will get back to you when I find the answer !
Brad Dougherty Staff
Hi Benoit,
Check out this page: vimeo.com/api/docs/player-js and player.vimeo.com/playground
Pablo Bollansée
Ok, I got it working !
Here's the code I use (with some comments added :P):
//First find all iframes
var iframes = $$('iframe');
//make a froogaloop for each of those frames
var froogaloops = new Array(iframes.length);
for(var i = 0, l = iframes.length; i < l; ++i)
{
var frame = iframes[i];
froogaloops[i] = new Froogaloop( frame );
}
function pauseAllVideos()
{
//For each froogaloop call the .api method
for(var i = 0, l = froogaloops.length; i < l; ++i)
{
froogaloops[i].api('api_pause');
}
}
Hope it helps !
Matthew Ferry
couldn't get this to work on my end. can you post your html as well?
Benoit Delaunay
I haven't been email-notified of your answer
It works perfectly. Thanks a lot ! My learning of js is too slow :)