Note that there are some explanatory texts on larger screens.

plurals
  1. POYoutube API automatically starts playing songs
    primarykey
    data
    text
    <p>I am using below code to play youtube shared videos but I want user to start the videos but as soon as the page loaded it starts playing the video. I want user to click on that link then it should start playing</p> <pre><code>&lt;script type="text/javascript"&gt; 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('&lt;?=$w ?&gt;'); ytplayer.addEventListener("onStateChange", "onytplayerStateChange"); } function onytplayerStateChange(newState) { setytplayerState(newState); } function minute(secVar0) { // The initial data, in seconds minVar = Math.floor(secVar0/60); // The minutes secVar = Math.floor(secVar0 % 60); // The 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 for the 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(); } } &lt;/script&gt; </code></pre> <p> </p> <pre><code>&lt;div id="ply"&gt; &lt;div id="ytapiplayer"&gt; &lt;/div&gt; &lt;script type="text/javascript"&gt; var params = { allowScriptAccess: "always", bgcolor: "#cccccc" }; var atts = { id: "myytplayer" }; swfobject.embedSWF("http://www.youtube.com/apiplayer?enablejsapi=1&amp;playerapiid=ytplayer", "ytapiplayer", "1", "1", "8", null, null, params, atts); &lt;/script&gt; &lt;/div&gt; &lt;div&gt; &lt;table class="controls"&gt; &lt;tr&gt; &lt;td&gt; &lt;a href="javascript:void(0);" onclick="pause()" id="playpause"&gt;&lt;img src="pause.jpg" id="playpauseimg" /&gt;&lt;/a&gt; &lt;/td&gt; &lt;td&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload