0

所以我使用加载YouTube播放列表:Youtube iframe api未捕获TypeError:对象不是函数吗?

event.target.loadPlaylist(videoIds); 

,我得到这个错误: enter image description here

怪异的一部分是约一秒钟, 然后休息播放列表加载罚款给我那个错误。

对不起继承人周围代码:

 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确认这一点。

+0

很难说没有看到它周围的代码......是否event.target真的引用了玩家? 'videoIds'是一个格式良好的数组吗?通过使用_console.log_显示它们进行检查。 – blex

+0

即使出现错误,所有视频列表都格式正确。 Console.log确认这一点。 Event.target是全局的,并在控制台中正确记录。 – gbachik

+0

它适用于我... [JS小提琴](http://jsfiddle.net/LMqDW/)。我会看看你的代码。 – blex

回答

1

我有同样的问题,但与loadVideoById。对我来说,问题是玩家还没有完全初始化,因此实际上没有方法loadVideoById。也许如果有人面临同样的问题,请尝试推迟电话并查看是否有帮助。

相关问题