我正在尝试设置我的代码,以便从上午12点到中午12点显示此YouTube播放列表,然后在中午12点到12点之间显示不同的播放列表,重复此过程。我看过SetIntervals和Date但仍然是使用java的新手,所以不确定如何实现它们。如果有人能给我一个例子,我会很感激。这是我目前的代码
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
height: '390',
width: '640',
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
var oldNumber = 0;
var NewNumber = 0;
function newRandomNumber(min, max) {
oldNumber = NewNumber;
NewNumber = Math.floor(Math.random() * max) + min;
if (NewNumber == oldNumber) {
newRandomNumber(min, max);
} else {
return NewNumber;
}
}
function onPlayerReady(event) {
next();
}
function next() {
player.loadPlaylist({
'listType': 'playlist',
'list': 'PLBLjQxqJYmcdjxmoFURusJpwbKs0XTSOy',
'autoplay': 1,
'controls': 0,
'index': newRandomNumber(0, 200),
});
player.setShuffle({
'shufflePlaylist': true
});
}
function onPlayerStateChange(event) {
if (event.data == YT.PlayerState.ENDED) {
next();
}
}
</script>
这是我试图将其改为
的另一个播放列表function next() {
player.loadPlaylist({
'listType': 'playlist',
'list': 'PLBLjQxqJYmcdjxmoFURusJpwbKs0XTSOy',
'autoplay': 1,
'controls': 0,
'index': newRandomNumber(0, 200),
});
player.setShuffle({
'shufflePlaylist': true
});
}