即使使用 document.getElementById('xyz').playVideo() 也无法控制 Youtube 嵌入 - 不是函数? [英] Can't control Youtube embed even with document.getElementById('xyz').playVideo() - not a function?

查看:34
本文介绍了即使使用 document.getElementById('xyz').playVideo() 也无法控制 Youtube 嵌入 - 不是函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

OK, I'm stuck and I don't know what's wrong even after following Google's docs and reading suggestions here on Stackoverflow. Why can't I control Youtube embeds in my web page?

如果我创建一个带有 的 HTML 文件正在:

If I create an HTML file with the <body> being:

<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();

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

Help! What am I doing wrong? Thanks.

推荐答案

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

OK, so here's the answer found in one tiny line of text on the API page: http://code.google.com/apis/youtube/js_api_reference.html

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

"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 笔记本电脑上进行开发,我做了以下事情:

So to allow me to continue to develop on my Mac laptop I did the following:

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

  1. Edited my /etc/hosts file to include an entry back to my localhost:

127.0.0.1   testhost.com

  • 编辑我的 /etc/apache2/httpd.conf 文件以添加一个指向我的开发目录的虚拟主机条目:

  • Edited my /etc/apache2/httpd.conf file to add a virtual host entry pointing back to my development directory:

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

  • 重启 Apache:

  • Restarted Apache:

    sudo apachectl restart
    

  • 通过我的新虚拟服务器浏览回我自己的本地主机:

  • Browsed back to my own localhost via my new virtual server:

    http://testhost.com
    

  • 瞧.现在完全有效.我可以查询播放器的页面:

    Voila. That totally works now. I can query the page for the player:

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

    哇!也不需要 onYouTubePlayerReady()

    这篇关于即使使用 document.getElementById('xyz').playVideo() 也无法控制 Youtube 嵌入 - 不是函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆