tsarahholmes
New Member
I want to create an Website that plays Random musicvideos from Youtube.I Have a probleme:First:After the Random Video select the Video URL needs to be paste in to the Youtube API (VideoID).Second:After paste it in Youtube API, the Script needs to detect when the "playing" Video is finished. After the Video the iframe needs to reload. => then a new video is selected.My attempt:\[code\]<script type="text/javascript"> var video=new Array() video[0] = "Phyg_uIPQII"; // Video 0 video[1] = "m6VojYGrnpg"; // Video 1 video[2] = "xT9sfmFSQfg"; // Video 2 video[3] = "faRlFsYmkeY"; // Video 3 var hoehe = "344"; // Video Hoehe var breite = "425"; // Video Breite var V = video.length; var showvideo=Math.round(Math.random()*(V-1)); document.write('<iframe width="'+breite+'" height="'+hoehe+'" src="http://www.youtube.com/embed/'+video[showvideo]+'" frameborder="0" allowfullscreen></iframe>');</script>\[/code\]\[code\]<script src="http://www.youtube.com/player_api"></script><script> // create youtube player var player; function onYouTubePlayerAPIReady() { player = new YT.Player('player', { height: '390', width: '640', videoId: '6Lh7Zg8WXwU', events: { 'onReady': onPlayerReady, 'onStateChange': onPlayerStateChange } }); } // autoplay video function onPlayerReady(event) { event.target.playVideo(); } // when video ends function onPlayerStateChange(event) { if(event.data =http://stackoverflow.com/questions/15653940/== 0) { alert('Random Again'); if (alert('Random Again') ) { window.location.reload(true); } } }</script>\[/code\]