Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/hadoop/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Youtube api 在播放器中加载新视频_Youtube Api - Fatal编程技术网

Youtube api 在播放器中加载新视频

Youtube api 在播放器中加载新视频,youtube-api,Youtube Api,我无法让下面的代码工作。我将在页面上放置一个播放器,并将其与视频一起加载。这正如预期的那样有效。然后,当用户单击其中一个(此处仅显示两个)时,我有许多其他视频的缩略图。这部分不起作用。我在控制台上收到一条错误消息,说ytplayer.loadvideobyID不是函数。我正在Firefox 26.0上测试这个 <html> <head> </head> <body> <table width="900" align="center" bord

我无法让下面的代码工作。我将在页面上放置一个播放器,并将其与视频一起加载。这正如预期的那样有效。然后,当用户单击其中一个(此处仅显示两个)时,我有许多其他视频的缩略图。这部分不起作用。我在控制台上收到一条错误消息,说ytplayer.loadvideobyID不是函数。我正在Firefox 26.0上测试这个

<html>
<head>
</head>
<body>
<table width="900" align="center" border="0" cellpadding="0" cellspacing="1">
  <tbody>       
<tr>
  <td>      
    <div id="ytplayer"></div>
  <td>   
</tr>   
<tr>
  <td>      
     <a href="javascript:void(0);" onclick="ytplayer.loadVideoById('tCnEH8MRrjE',0);"><img src="http://img.youtube.com/vi/tCnEH8MRrjE/hqdefault.jpg" width="176" height="132"></a>     
  </td>   
</tr>   
<tr>
       <td>     
      <a href="javascript:void(0);" onclick="ytplayer.loadVideoById('lqdFrGFo6SQ',0);"><img src="http://img.youtube.com/vi/lqdFrGFo6SQ/hqdefault.jpg" width="176" height="132"></a>    
   </td>   
</tr>   
  </tbody>
</table>
    <script  type="text/javascript">
     // Replace the 'ytplayer' element with an <iframe> and
      // YouTube player after the API code downloads.

      var player;
      function onYouTubeIframeAPIReady() 
      {
        player = new YT.Player('ytplayer', 
        {
          height: '390',
          width: '640',
          videoId: 'tCnEH8MRrjE',
        });
      }  

     // Load the IFrame Player API code asynchronously.
     var tag = document.createElement('script');
     tag.src = "https://www.youtube.com/player_api";
     var firstScriptTag = document.getElementsByTagName('script')[0];
     firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
   </script>
  </body>
</html>

//用and替换“ytplayer”元素
//YouTube播放器的API代码下载后。
var播放器;
函数onyoutubeiframeapiredy()
{
player=新的YT.player('ytplayer',
{
高度:“390”,
宽度:“640”,
videoId:'TCNEH8MRJE',
});
}  
//异步加载IFrame播放器API代码。
var tag=document.createElement('script');
tag.src=”https://www.youtube.com/player_api";
var firstScriptTag=document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(标记,firstScriptTag);

您将HTML元素的ID(
“ytplayer”
)与Javascript变量的名称(
player
)混淆了。将
ytplayer.loadVideoById(…)
更改为
player.loadVideoById(…)

或者,您也可以使用相同的符号(无论是
player
还是
ytplayer
)来表示所有的玩家