我有一個數組中的視頻列表,我希望能夠讓播放器在當前播放結束後播放列表中的另一個視頻。我遇到的問題是它重複播放同一個視頻,而不是選擇新的視頻播放。我一直在尋找類似的問題,並沒有找到任何可以使其工作的東西。任何意見,將不勝感激!如何從列表中播放隨機視頻?
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
// 3. This function creates an <iframe> (and YouTube player)
// after the API code downloads.
function rotateYT() {
var videos = [
'be0T_owA1PU',
'Kp7eSUU9oy8',
'Th0V-fxo9CE',
];
var index=Math.floor(Math.random() * videos.length);
return videos[index];
}
var player;
function onYouTubeIframeAPIReady() {
var videoID = rotateYT();
player = new YT.Player('player', {
height: '300',
width: '300',
videoId: videoID,
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
// 4. The API will call this function when the video player is ready.
function onPlayerReady(event) {
player.setPlaybackRate(1);
event.target.playVideo();
}
// 5. This should play another random video
function onPlayerStateChange(event) {
if(event.data === 0) {
event.target.setShuffle(true);
event.target.playVideo();
}
}
我可能把代碼中的錯誤所以這裏的的jsfiddle香港專業教育學院一直在努力
https://jsfiddle.net/bbasham/L20k7x1o/2/
問題是什麼'javascript'問題? – guest271314