I have several YouTube videos on one page, I wish that when I play in one, if another video was rolling, pause it. It's possible? Without reloading the page ...
I have several YouTube videos on one page, I wish that when I play in one, if another video was rolling, pause it. It's possible? Without reloading the page ...
To do this you need to have access to YouTube player events.
function onYouTubePlayerReady(playerId) {
var ytplayer = document.getElementById("MyYouTubePlayer");
ytplayer.addEventListener("onStateChange", "onytplayerStateChange");
}
function onytplayerStateChange(newState) {
switch (newState) {
case 0:
// Encerrado
break;
case -1:
// Não iniciado
break;
case 1:
// Em reprodução
break;
case 2:
// Pausado
break;
case 3:
// Armazenando em buffer
break;
case 5:
// Vídeo iniciado
break;
}
}