Detect when video has changed - YouTube iFrame API
<p>I have some kind of slider with a YouTube playlist in the background. I'd like to know when the video has changed, so I can change the slider text to the right text.</p>

<p>I've searched the API page (<a href="https://developers.google.com/youtube/iframe_api_reference#Events" rel="nofollow">https://developers.google.com/youtube/iframe_api_reference#Events</a>) and can't seem to find an event that fires when the video changes. Is there one?</p>

<p>Here's my code until now.</p>

<pre><code>var tag = document.createElement('script');

tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

window.player;
var player;

var playlistVideos = new Array();
jQuery('#playlistSlider span').each(function(){
    playlistVideos.push(jQuery(this).html());
})

//console.log(playlistVideos)

function onYouTubePlayerAPIReady() {
    player = new YT.Player('playlistSlider', {
        height: '390',
        width: '640',
        loadPlaylist:{
            listType:'playlist',
            list:playlistVideos,
            index:parseInt(0),
            //suggestedQuality:'small'
        },
        events: {
            'onReady': onPlayerReady,
            //'onStateChange': onPlayerStateChange
        },
    });
}
function onPlayerReady(event) {
    event.target.loadPlaylist(playlistVideos);
    event.target.mute();
    event.target.setLoop(true);
}
</code></pre>

<p>A bonus would also be to know what is the current video playing (index).</p>