我试图在完成最后一个视频后获得第一个视频我正在使用youtube我会播放视频继续但是在最后一个视频结束后它没有获得第一个视频这里我正在处理的代码
<div id="player"></div>
<script src="http://www.youtube.com/iframe_api"></script>
<script>
/**
* Put your video IDs in this array
*/
var videoIDs = [
'MCgODvsmrmY',
'RdyXFNgZdCw'
];
var player, currentVideoId = 0;
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
height: '768',
width: '1026',
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
function onPlayerReady(event) {
event.target.loadVideoById(videoIDs[currentVideoId]);
node.requestFullScreen();
document.fullScreen;
}
function onPlayerStateChange(event) {
if (event.data == YT.PlayerState.ENDED) {
currentVideoId++;
if (currentVideoId < videoIDs.length) {
player.loadVideoById(videoIDs[currentVideoId]);
}
}
}
</script>
答案 0 :(得分:0)
将上一个视频播放完毕后,将onPlayerStateChange
功能更改为重置currentVideoId
:
currentVideoId++;
if (currentVideoId >= videoIDs.length) {
currentVideoId = 0; }
player.loadVideoById(videoIDs[currentVideoId]);