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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.