<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script type="text/javascript">
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
height: '600',
width: '100%',
videoId: 'CHNdRDjeopE',
playerVars : {
'autoplay': 0,
},
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
function onPlayerReady(event) {
// event.target.playVideo();
}
function onPlayerStateChange(event) {
if (event.data == YT.PlayerState.PLAYING) {
console.log("Está reproduciendo, lanzar evento que se quiera");
}
if (event.data == YT.PlayerState.PAUSED) {
console.log("Se ha pausado, lanzar evento que se quiera");
}
}
</script>
</head>
<body>
<div id="player"></div>
</body>
</html>
Los eventos que se pueden capturar son:
YT.PlayerState.ENDED
YT.PlayerState.PLAYING
YT.PlayerState.PAUSED
YT.PlayerState.BUFFERING
YT.PlayerState.CUED
No hay comentarios:
Publicar un comentario