Jump to content

Youtube API


slipvayne

Recommended Posts

I'm pretty new at javascript... this is really the first code I'm trying to make using javascript and I've come to a little trouble.

 


<script type="text/javascript">

var params = { allowScriptAccess: "always", bgcolor: "#FFFFFF"};
var atts = { id: "ytplayer" };
swfobject.embedSWF("http://www.youtube.com/v/<?=$embedid?>&enablejsapi=1&playerapiid=ytplayer&autoplay=1&color1=0x000000&color2=0xB90000", "myContent", "480", "360", "9.0.0", "expressInstall.swf");

ytplayer.addEventListener("onStateChange", "onPlayerStateChange");
function onPlayerStateChange(newState) {
ytState=newState;
if(ytState==0) window.location.reload();
}

function onYouTubePlayerReady(playerId) {
ytplayer = document.getElementById("ytplayer");    
ytplayer.addEventListener("onStateChange", "onPlayerStateChange");
}


</script>

<div id="myContent">
<p>Alternative content</p>
</div>

 

Now, if ytState == 0, that means the video has ended play. I'm trying to test this out, by having the page reload when the video ends, using window.location.reload(); but it is not working. Any help or advice is appreciated.

Link to comment
https://forums.phpfreaks.com/topic/211408-youtube-api/
Share on other sites

I changed it, and no, there was no alert. :/

 

Here is the link if you want to check it out:

http://zwars.org/Vaduz/index.php?p=shuffle

 

Could it be because my script is in between the body tags and not the head tags? I always read that it should be in the head tags but I've always put my javascripts in the body of my documents and never had any problems.

 

 

Link to comment
https://forums.phpfreaks.com/topic/211408-youtube-api/#findComment-1105011
Share on other sites

  • 2 weeks later...

I fixed my code, so that there is no error. But nothing happens, the page does not refresh when the video ends. :/

 

Here is what I currently have:

 


<script type="text/javascript">

var params = { allowScriptAccess: "always", bgcolor: "#FFFFFF"};
var atts = { id: "myytplayer" };
swfobject.embedSWF("http://www.youtube.com/v/<?=$embedid?>&enablejsapi=1&playerapiid=myytplayer&autoplay=1&color1=0x000000&color2=0xB90000", "myContent", "480", "360", "9.0.0", "expressInstall.swf");


function onYouTubePlayerReady(playerId) {
  ytplayer = document.getElementById("myytplayer");
  ytplayer.addEventListener("onStateChange", "onytplayerStateChange");
}


function onytplayerStateChange(newState) {
   if (newstate = 0) {

window.location.reload()

   }
}

</script>

 

Although check the source on http://www.zwars.org/Vaduz/?p=shuffle because I may be changing the code around on there.

Link to comment
https://forums.phpfreaks.com/topic/211408-youtube-api/#findComment-1110360
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.