我正在尝试在完成上一个视频后获取第一个视频,我正在使用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>

最佳答案

更改您的onPlayerStateChange函数,以在最后一个视频结束时将currentVideoId重置为0:

currentVideoId++;
if (currentVideoId >= videoIDs.length) {
    currentVideoId = 0; }

player.loadVideoById(videoIDs[currentVideoId]);

10-07 18:20