Can't control Youtube embed even with document.getElementById('xyz').playVideo() - not a function?

后端 未结 4 654
悲哀的现实
悲哀的现实 2021-01-06 14:24

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

4条回答
  •  鱼传尺愫
    2021-01-06 14:55

    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

    "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."

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

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

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

      
          ServerName testhost.com
          DocumentRoot /Users/amy/flashproj
          
              AllowOverride all
              Options MultiViews Indexes FollowSymLinks
              Allow from All
          
      
      
    3. Restarted Apache:

      sudo apachectl restart
      
    4. 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!
    

    Whew! No onYouTubePlayerReady() required either!

提交回复
热议问题