Is there a way to make the next video play automatically using the loadPlaylist
option?
I've tried implementing this code but unfortunately, it doesn't work and the video won't play:
<div id="player"></div>
<script>
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: '390',
width: '640',
loadPlaylist:{
listType:'playlist',
list:['4Ivdp8kj_0U','4MJRS-cLozU'],
index:parseInt(0),
suggestedQuality:'small'
},
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
function onPlayerReady(event) {
event.target.playVideo();
}
var done = false;
function onPlayerStateChange(event) {
if (event.data == YT.PlayerState.PLAYING && !done) {
// setTimeout(stopVideo, 60000);
done = true;
}
}
function stopVideo() {
player.stopVideo();
}
</script>
I'm aiming for a similar effect as shown in this example: http://www.youtube.com/watch?v=0DdCoNbbRvQ&list=RD02_VTY8ftr1vY
Thank you in advance.