JSFiddle - React, Tailwind, and code Playground

by ko echos

HTML

<div id="player"></div>

JavaScript

// 2. This code loads the IFrame Player API code asynchronously.
      var tag = document.createElement('script');

      tag.src = "https://www.youtube.com/iframe_api";
      var firstScriptTag = document.getElementsByTagName('script')[0];
      firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
      
      var playLists = ["qPmHKFgJybc","oJnhoD-c0xU","Use3AepKNg8"];  // 영상 플레이 아이디 배열
      var pcnt = playLists.length;

      // 3. This function creates an <iframe> (and YouTube player)
      //    after the API code downloads.
      var player;
      function onYouTubeIframeAPIReady() {
        player = new YT.Player('player', {
          height: '360',
          width: '640',
          
          videoId : 'qPmHKFgJybc',
          
          events: {
            'onReady': onPlayerReady,
            'onStateChange': onPlayerStateChange,
          }
        });
      }

      // 4. The API will call this function when the video player is ready.
      function onPlayerReady(event) {
        player.loadPlaylist({
         	mute:1,
          enablejsapi:1,          
          autoplay : 1,          
          //loop : 1,
          playlist : playLists,
        });
        
	      event.target.playVideo();
      }
      
      
//      var done = false;
      function onPlayerStateChange(event) {
        
        if (event.data == YT.PlayerState.ENDED) {
          //done = true;
          console.log('Video Finished');
          
          player.loadPlaylist(playLists, 0);
        }
      }
     
			function setPlayerFirst(){
      	
      }       
      
      function stopVideo() {
        player.stopVideo();
      }