我正在使用YouTube API,我试图在我的视频结束时设置onStateChange来洗牌我的播放列表并从0开始…这是我目前得到的
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
height: '390',
width: '640',
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
function onPlayerReady(event) {
player.loadPlaylist({'listType': 'playlist', 'list': 'PLF776D41D8211F340','index': '0','startSeconds': '0','suggestedQuality': 'hd720'});
}
var done = false;
function onPlayerStateChange(event) {
if (event.data == YT.PlayerState.PLAYING && done == false) {
player.setShuffle(true);
player.playVideoAt(0);
done = true;
}else if (event.data == YT.PlayerState.ENDED && done == true) {
player.setShuffle(true);
player.playVideoAt(0);
done = false;
}
}
我哪里做错了?
您需要在onPlayerReady
功能中包含player.playVideoAt(0)
function onPlayerReady(event) {
player.loadPlaylist({'listType': 'playlist', 'list': 'PLF776D41D8211F340','index': '0','startSeconds': '0','suggestedQuality': 'hd720'});
player.playVideo();
}
当你正在播放播放列表中的第一个视频时,为什么不使用player.playVideo()
来代替。
我没有包括player.setShuffle(true)
,因为它目前不工作(已知的错误)-见这篇文章