How does Quora use the Youtube Javascript API to pause a playing video when the user plays another video on the same page?
-
-
Answer:
I built the video feature on Quora. It's pretty easy to pause the playing YouTube video when the user clicks on another video. You just need to catch the click event and tell all YouTube players on the page to pause themselves before starting the video the user actually clicked on. You can do it with something like this: // Store a reference to each YouTube player DOM element in an array. // Here I'll just assume two players and hard-code them. var ytplayer1 = document.getElementById("playerId1"); var ytplayer2 = document.getElementById("playerId2"); var players = [ytplayer1, ytplayer2]; // Assuming that all YouTube players on the page have the class "player" $(".player").click(function(event) { // Pause all videos for(var i = 0; i < players.length; i++) { players[i].pauseVideo(); } // Play the clicked video $(event.target).playVideo(); });
Feross Aboukhadijeh at Quora Visit the source
Related Q & A:
- How to properly reference a user control and dynamically add it to page?Best solution by Stack Overflow
- How do I permanently block a user forever? I mean, find or enter the username, when the user isnt on my list?Best solution by Yahoo! Answers
- How do I send a private video on youtube?Best solution by Yahoo! Answers
- How do you make a music video for youtube?Best solution by Yahoo! Answers
- How will i make a edited video in YouTube?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.