How to Play a Playlist using YouTube JavaScript API

前端 未结 3 1711
花落未央
花落未央 2021-02-02 00:18

I\'m trying to play a youtube playlist using this JavaScript API for iframe-embeds introduced this January. http://apiblog.youtube.com/2011/01/introducing-javascript-player-api-

3条回答
  •  无人共我
    2021-02-02 01:04

    I found the answer.

    Just add 'playlist' to your playerVars and the playlist String|Array.

    playerVars: { 'autoplay': 0, 'controls': 1, 'playlist':['your_video_id', '...']},

    Like de example below:

    var player;
    function onYouTubePlayerAPIReady() {
    player = new YT.Player('player', {
      height: '390',
      width: '640',
      videoId: 'your_video_id',
      playerVars: { 'autoplay': 0, 'controls': 1, 'playlist':['your_video_id', '...']},
      events: {
        'onReady': onPlayerReady,
        'onStateChange': onPlayerStateChange
      }
    });
    }
    

提交回复
热议问题