javascript - Youtube API automatically starts playing songs -


i using below code play youtube shared videos want user start videos page loaded starts playing video. want user click on link should start playing

<script type="text/javascript">      function updatehtml(elmid, value) {       document.getelementbyid(elmid).innerhtml = value;     }      function setytplayerstate(newstate) {       if(newstate==3 || newstate==-1)       {         $('ld').show();       }       else       {         $('ld').hide();       }     }      function onyoutubeplayerready(playerid) {       ytplayer = document.getelementbyid("myytplayer");       setinterval(updateytplayerinfo, 250);       updateytplayerinfo();       loadnewvideo('<?=$w ?>');       ytplayer.addeventlistener("onstatechange", "onytplayerstatechange");     }      function onytplayerstatechange(newstate) {       setytplayerstate(newstate);     }     function minute(secvar0)     {                          // initial data, in seconds minvar = math.floor(secvar0/60);  // minutes secvar = math.floor(secvar0 % 60);              // balance of seconds return minvar+":"+secvar;     }     function updateytplayerinfo() {        updatehtml("videoduration", minute(getduration()));       updatehtml("videotime", minute(getcurrenttime()));       //updatehtml("startbytes", );        var sbyte=getstartbytes();       var tbyte=getbytestotal();       var lbyte= getbytesloaded();        var l=math.floor(400*lbyte/tbyte);        //$('loaded').style.width=l+"px";         var c=getcurrenttime();       var t=getduration();        slider.setvalue(c/t);     }      // functions api calls     function loadnewvideo(id, startseconds) {       if (ytplayer) {         ytplayer.loadvideobyid(id, parseint(startseconds));       }     }      function cuenewvideo(id, startseconds) {       if (ytplayer) {         ytplayer.cuevideobyid(id, startseconds);       }     }      function play() {       if (ytplayer) {         ytplayer.playvideo();         $('playpause').onclick=function(){pause()};         $('playpauseimg').src='pause.jpg';       }     }      function pause() {       if (ytplayer) {         ytplayer.pausevideo();         $('playpause').onclick=function(){play()};         $('playpauseimg').src='play.jpg';       }     }      function stop() {       if (ytplayer) {         ytplayer.stopvideo();       }     }      function getplayerstate() {       if (ytplayer) {         return ytplayer.getplayerstate();       }     }      function seekto(seconds) {       if (ytplayer) {       var t=getduration();       var s;       s=t*seconds;         ytplayer.seekto(s, true);       }     }      function getbytesloaded() {       if (ytplayer) {         return ytplayer.getvideobytesloaded();       }     }      function getbytestotal() {       if (ytplayer) {         return ytplayer.getvideobytestotal();       }     }      function getcurrenttime() {       if (ytplayer) {         return ytplayer.getcurrenttime();       }     }      function getduration() {       if (ytplayer) {         return ytplayer.getduration();       }     }      function getstartbytes() {       if (ytplayer) {         return ytplayer.getvideostartbytes();       }     }      function mute() {       if (ytplayer) {         ytplayer.mute();       }     }      function unmute() {       if (ytplayer) {         ytplayer.unmute();       }     }      function getembedcode() {       alert(ytplayer.getvideoembedcode());     }      function getvideourl() {       alert(ytplayer.getvideourl());     }      function setvolume(newvolume) {       if (ytplayer) {         ytplayer.setvolume(newvolume);       }     }      function getvolume() {       if (ytplayer) {         return ytplayer.getvolume();       }     }      function clearvideo() {       if (ytplayer) {         ytplayer.clearvideo();       }     }   </script> 

<div id="ply"> <div id="ytapiplayer">  </div> <script type="text/javascript">    var params = { allowscriptaccess: "always", bgcolor: "#cccccc" };    var atts = { id: "myytplayer" };   swfobject.embedswf("http://www.youtube.com/apiplayer?enablejsapi=1&playerapiid=ytplayer",                       "ytapiplayer", "1", "1", "8", null, null, params, atts);  </script> </div>  <div> <table class="controls"> <tr> <td>      <a href="javascript:void(0);" onclick="pause()" id="playpause"><img src="pause.jpg" id="playpauseimg" /></a> </td> <td> 

pass autoplay: 0 1 of parameters.

var params = { allowscriptaccess: "always", bgcolor: "#cccccc", autoplay: 0 }; var atts = { id: "myytplayer" }; // etc... 

http://code.google.com/apis/youtube/player_parameters.html#autoplay


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -