本文介绍了YouTube API — 不触发“onYouTubePlayerReady()"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,这就是我应该如何设置 YouTube API:

From what I've read, this is how I should setup the YouTube API:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta content='text/html;charset=UTF-8' http-equiv='content-type' />
    <title>Youtube Player</title>
    <script src="jquery.js" type="text/javascript"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js" type="text/javascript"></script>
    <script type="text/javascript" charset="utf-8">
      function onYouTubePlayerReady(id) {
        console.log("onYouTubePlayerReady() Fired!");
        var player = $("#youtube_player").get(0);
      }

      var params = { allowScriptAccess: "always" };
      var atts = { id: "youtube_player" };
      swfobject.embedSWF("http://www.youtube.com/apiplayer?enablejsapi=1",
                         "youtube", "425", "356", "8", null, null, params, atts);

    </script>
  </head>
  <body>
    <div id="youtube"></div>
  </body>
</html>

然而,'onYouTubePlayerReady()' 根本不会触发,如果我手动获取播放器的引用,很多方法是未定义的;例如,cueVideoById() 有效,但 playVideo() 无效.

However, 'onYouTubePlayerReady()' doesn't fire at all, and if I manually get a reference to the player, a lot of methods are undefined; for example, cueVideoById() works, but playVideo() doesn't.

我该如何解决这个问题?

How can I fix this problem?

推荐答案

文档:

注意:要测试任何这些调用,您必须在网络服务器上运行您的文件,因为 Flash 播放器会限制本地文件和互联网之间的调用.

这篇关于YouTube API — 不触发“onYouTubePlayerReady()"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 02:29