Autoplay multiple YouTube videos on mute at once

前端 未结 1 1515
一个人的身影
一个人的身影 2021-01-26 07:51

I am trying to make a webpage that uses the YouTube iframe API to display multiple videos which start playing automatically on load. I want 3 of the 4 videos to start playing in

相关标签:
1条回答
  • 2021-01-26 08:40

    Kindly change your code:

    From:

    new YT.Player(players[i], {
        playerVars: {
            'autoplay': 1,
            'modestbranding': 1,
            'controls': 1,
            events: {
            'onReady': onPlayerReady
            }
        },
        videoId: players[i].dataset.id
    });
    

    To

    new YT.Player(players[i], {
        playerVars: {
            'autoplay': 1,
            'modestbranding': 1,
            'controls': 1},
            events: {
            'onReady': onPlayerReady
        },
        videoId: players[i].dataset.id
    });
    

    Base on the sample code given by google. Events element is outside the playerVars element. Here is the link for the supported list of parameters int playerVars element.

    function onYouTubeIframeAPIReady() {
        var player;
        player = new YT.Player('player', {
            videoId: 'M7lc1UVf-VE',
            playerVars: { 'autoplay': 1, 'controls': 0 },
            events: {
                'onReady': onPlayerReady,
                'onPlaybackQualityChange': onPlayerPlaybackQualityChange,
                'onStateChange': onPlayerStateChange,
                'onError': onPlayerError
            }
        });
    }
    

    See this jsfiddle as example.

    0 讨论(0)
提交回复
热议问题