DZone 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

Randall has posted 3 posts at DZone. View Full User Profile

Autoplay YouTube SWF Using API, Not Autoplay=1

  • submit to reddit
        You need to

1. Download SWFobject, not link to YouTube's -

2. Change swfobject.embedSWF(" 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"
<html xmlns="" xml:lang="en" lang="en">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
      YouTube Javascript API Autostart
    <script src="swfobject.js" type="text/javascript"></script>

    <script type="text/javascript">
    <div id="ytapiplayer">
      You need Flash player 8+ and JavaScript enabled to view this video.
    <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" };
                         "ytapiplayer", "425", "344", "8", null, null, params, atts);