gpt4 book ai didi

javascript - 即使使用 document.getElementById ('xyz' ).playVideo() 也无法控制 Youtube 嵌入 - 不是函数?

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:38:29 25 4
gpt4 key购买 nike

好吧,我被卡住了,即使在遵循了 Google 的文档并阅读了 Stackoverflow 上的建议之后,我也不知道出了什么问题。为什么我无法控制我网页中的 Youtube 嵌入?

如果我用 创建一个 HTML 文件:

<object id="o1" width="480" height="295">
<param name="movie"
value="http://www.youtube.com/v/qCTLCNmnlKU&hl=en_US&fs=1&enablejsapi=1&">
</param>
<param name="allowFullScreen" value="true"></param>
<param name="allowscriptaccess" value="always"></param>
<embed id="e1"
src="http://www.youtube.com/v/qCTLCNmnlKU&hl=en_US&fs=1&enablejsapi=1&"
type="application/x-shockwave-flash"
allowscriptaccess="always" allowfullscreen="true" width="480" height="295">
</embed>
</object>

即使我尝试这样做:

// I get an object. Yay.

document.getElementById('e1');

// This generates "...playVideo is not a function"

document.getElementById('e1').playVideo();

帮助!我究竟做错了什么?谢谢。

最佳答案

好的,这是在 API 页面上的一小行文本中找到的答案:http://code.google.com/apis/youtube/js_api_reference.html

"Note: To test any of these calls, you must have your file running on a webserver, as the Flash player restricts calls between local files and the internet."

所以为了让我继续在我的 Mac 笔记本电脑上开发,我做了以下事情:

  1. 编辑了我的 /etc/hosts 文件以包含返回到我的本地主机的条目:

    127.0.0.1   testhost.com
  2. 编辑了我的 /etc/apache2/httpd.conf 文件以添加指向我的开发目录的虚拟主机条目:

    <VirtualHost *:80>
    ServerName testhost.com
    DocumentRoot /Users/amy/flashproj
    <Directory /Users/amy/flashproj>
    AllowOverride all
    Options MultiViews Indexes FollowSymLinks
    Allow from All
    </Directory>
    </VirtualHost>
  3. 重新启动 Apache:

    sudo apachectl restart
  4. 通过我的新虚拟服务器浏览回我自己的本地主机:

    http://testhost.com

瞧。现在完全可以了。我可以查询播放器的页面:

document.getElementById('e1');                // OK
document.getElementById('e1').playVideo(); // OK!

哇!也不需要 onYouTubePlayerReady()!

关于javascript - 即使使用 document.getElementById ('xyz' ).playVideo() 也无法控制 Youtube 嵌入 - 不是函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2217543/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com