TypeError: player.b is undefined. How do I fix that?

This is coming up in the web console.

Code:
https://jsfiddle.net/0bnrg3k1/2/

    function onPlayerStateChange(event) {
    const player = event.target;
    const playerVars = player.b.b.playerVars;
    if (playerVars.loop && event.data === YT.PlayerState.ENDED) {
      player.seekTo(playerVars.start);
    }
  }

whats going on mate?

give me a bit more info, all i see is a video playing for a few seconds

This is coming up in the web console.

alright mate when does it give this error? is it after you press play?

yes, it is after I press play.

looks like you’ve copied the code from somewhere and tried to put it together?

dont do this it will just confuse you more and waste other peoples time

This is actually a bit further along from where i am in the journey, and thus above my head a bit, but if you remove one of the 'b’s on playerVars, and rerun, the error disappears. Just looked a bit weird to have b property of player b? If you’re just looking for the error to go away, that seems to do the trick.

There’s still an error.

It’s fixed.
https://jsfiddle.net/3c5fu2e6/

(function manageCover() {
   "use strict";

   function hide(el) {
      el.classList.add("hide");
   }

   function coverClickHandler(evt) {
      const cover = evt.currentTarget;
      hide(cover);
   }
   const cover = document.querySelector(".jacketc ");
   cover.addEventListener("click", coverClickHandler);
}());
const videoPlayer = (function makeVideoPlayer() {
   "use strict";


   const playerVars = {
      autoplay: 1,
      controls: 1,
      showinfo: 1,
      rel: 0,
      iv_load_policy: 3,
      cc_load_policy: 0,
      fs: 0,
      disablekb: 1,
      loop: true,
      start: 200,
      end: 204
   };

   function onPlayerReady(event) {
      const player = event.target;
      player.setVolume(50); // percent
   }

   function onPlayerStateChange(event) {
      const player = event.target;
      //  const playerVars = player.b.b.playerVars;
      if (playerVars.loop && event.data === YT.PlayerState.ENDED) {
         player.seekTo(playerVars.start);
      }
   }

   function addVideo(video) {
      new YT.Player(video, {
         width: 606,
         height: 344,
         videoId: video.dataset.id,
         host: "https://www.youtube-nocookie.com",
         // playerVars: {
         //   ...
         // },
         playerVars,

         events: {
            "onReady": onPlayerReady,
            "onStateChange": onPlayerStateChange
         }
      });
   }

   function init(opts) {
      load.js("https://www.youtube.com/player_api").then(function () {
         YT.ready(function () {
            addVideo(opts.video);
         });
      });
   }
   return {
      init
   };
}());
1 Like