Youtube iframe API has an event for detecting the end of a video. If used with an embedded playlist, this event fires after every video. I wish to only detect the end of the last video in a playlist.
This is my attempt:
if (event.data == YT.PlayerState.ENDED && currentIndex == playlist.length - 1 ){
alert('Playlist finished.');
}
The problem his this will trigger twice. At the end of the second to last video in the playlist, the player state is ENDED and the playlist index increases by one, thus triggering too early. It also triggers at the end of the last video in the playlist which is the only intended result.