не могу вставить видеоплеер youtube

не получается вставить видеоплеер ютуба через апи, делаю все по инструкции. но плеер не создается. В девтулзах скрипт к которому делается запрос создается. В консоле никаких ошибок нету.

файл с разметкой pug

section.main-house
    .container-small
      .main-house__content
        h2.h2.main-house__title.title.title--pink ДОМ
        .main-house__main
          .video-block
            .video
              .video__player(id="js-player")
              .video__preview
                img(src="img/images/preview.jpg")
              .video__button-wrapper
                button.video__button


файл с js

export default () => {
  const tag = document.createElement('script');
  tag.src = 'https://www.youtube.com/iframe_api';
  const firstScriptTag = document.getElementsByTagName('script')[0];
  firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

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

  // 4. The API will call this function when the video player is ready.
  function onPlayerReady(event) {
    event.target.playVideo();
  }

  // 5. The API calls this function when the player's state changes.
  //    The function indicates that when playing a video (state=1),
  //    the player should play for six seconds and then stop.
  let done = false;
  function onPlayerStateChange(event) {
    if (event.data == YT.PlayerState.PLAYING && !done) {
      setTimeout(stopVideo, 6000);
      done = true;
    }
  }
  function stopVideo() {
    player.stopVideo();
  }
};

Ответы (0 шт):