Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Autoplay YouTube SWF using API, not autoplay=1 (See related posts)

You need to

1. Download SWFobject, not link to YouTube's - http://code.google.com/p/swfobject/

2. Change swfobject.embedSWF("http://www.youtube.com/v/OdqhDcAoQuc to the URL of your video

the setTimeout is very important, it will not work without it - but you may be able to set the timer to less than 5000 milliseconds

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>
      YouTube Javascript API Autostart
    </title>
    <script src="swfobject.js" type="text/javascript"></script>


    <script type="text/javascript">
setTimeout('myytplayer.playVideo()',5000);
    </script>
  </head>
  <body>
  <div>
    <div id="ytapiplayer">
      You need Flash player 8+ and JavaScript enabled to view this video.
    </div>
    <script type="text/javascript">
      // allowScriptAccess must be set to allow the Javascript from one domain to access the swf on the youtube domain
      var params = { allowScriptAccess: "always" };
     // this sets the id of the object or embed tag to 'myytplayer'. You then use this id to access the swf and make calls to the player's API
      var atts = { id: "myytplayer" };
      swfobject.embedSWF("http://www.youtube.com/v/OdqhDcAoQuc&amp;border=0&amp;enablejsapi=1&amp;playerapiid=ytplayer", 
                         "ytapiplayer", "425", "344", "8", null, null, params, atts);
    </script>

  </body>
</html>

Comments on this post

asil posts on Oct 23, 2009 at 16:39
Thank you for sharing and technical informations. This article I want to share with my other friends. Regards.

- - - - - - - - - - - - - - - - - - - - - - - -
Eglence icin Chat, Sohbet deneyin.
ohyeah posts on Nov 03, 2009 at 10:16
Sounds good! I wonder if you like the basketball games? Im the sneaker collector, and I like Basketball Shoes so much. That’s why you saw me here. Also, my sister ask me to find some UGG Boots useful news, can you help me? Thanks!
jingren posts on Nov 05, 2009 at 09:25
The information you posted about replica handbags
replica bags
ed hardy
ed hardy clothing
ralph lauren polo
juicy couture is so useful, I am expecting for your next post.


You need to create an account or log in to post comments to this site.


Click here to browse all 7284 code snippets

Related Posts