Reputation: 1706
so I'm loading a youtube playlist using:
event.target.loadPlaylist(videoIds);
and I'm getting this error:
The weird part is the playlist loads fine for about one second, and then breaks giving me that error.
sorry heres the surrounding code:
window.tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
window.firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
// 3. This function creates an <iframe> (and YouTube player)
// after the API code downloads.
// window.player;
window.onYouTubeIframeAPIReady = function() {
player = new YT.Player('player', {
height: '480',
width: '853',
playerVars: {
controls: 1,
modestbranding: 1,
playsinline: 1,
showinfo: 1,
iv_load_policy: 3,
rel: 0
},
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
window.onPlayerReady = function(event) {
//wierd 404 errors sometimes
event.target.loadPlaylist(videoIds, 0, 0, 'large');
event.target.playVideo();
}
window.onPlayerStateChange = function(event) {
console.log('the state changed: '+ event.data);
if (event.data === 1) {
console.log(event.target.getDuration());
globalYoutubePlayerCounter++;
console.log('youtube player count: ' +globalYoutubePlayerCounter);
}
if (globalYoutubePlayerCounter >= 6) {
/* load the next set of videos */
globalYoutubePlayerCounter = 0;
console.log('playlist ended');
if (that.finalTrackList.length > 0) {
that.getNextTenMusic(event.target);
}else{
// recall for general searches;
// that.getNextTenGeneral(event.target);
}
/* load the next set of videos */
}
}
All video list is formatted correctly even when I get the error. Console.log confirms this.
Upvotes: 0
Views: 1999
Reputation: 107
I had the same issue but with loadVideoById
. For me, the problem was that the player hadn't fully initialized and therefore there really was no method loadVideoById. Maybe if someone faces the same problem, try postponing the call and see if that helps.
Upvotes: 1