所以我使用以下方式加载 YouTube 播放列表:
event.target.loadPlaylist(videoIds);
我收到此错误:
奇怪的是播放列表加载良好大约一秒钟, 然后中断给我这个错误。
抱歉,这是周围的代码:
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 */
}
}
即使出现错误,所有视频列表的格式也正确。 Console.log 证实了这一点。
最佳答案
我也遇到了同样的问题,但使用了 loadVideoById
。对我来说,问题是播放器尚未完全初始化,因此实际上没有方法 loadVideoById。也许如果有人遇到同样的问题,请尝试推迟通话,看看是否有帮助。
关于javascript - YouTube iframe api 未捕获类型错误 : object is not a function?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24786577/