I am using the following code, it is suppose to put a random value for firstVId but it is not working why?
<script src="http://www.youtube.com/player_api"></script>
<script>
Math.randomB = function(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
var array = [4L5g2kN9oUU, NiyUYuO-n38, cxYFNrVc81I];
var firstVId = array[Math.randomB(0, array.length - 1)];
var secondVId = '6Z1y3b46A1k';
var bPlayedSecondTime = false;
// create youtube player
var player;
function onYouTubePlayerAPIReady() {
player = new YT.Player('player', {
height: '390',
width: '640',
videoId: firstVId,
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
// autoplay video
function onPlayerReady(event) {
event.target.playVideo();
}
// when video ends
function onPlayerStateChange(event) {
if(event.data === 0) {
if(bPlayedSecondTime == false)
{
player.loadVideoById(secondVId);
bPlayedSecondTime = true;
event.target.playVideo();
}
}
}
</script>