Questions about the YouTube player_api code


No - the addVideo line in the init function.


Remove the whole thing?
addVideo(playerVars, opts);


No. Here’s what I said just a short time ago about it.


Got it:


The plan is to give width/height information to loadPlayer, which gives it to videoPlayer’s init, which gives it to addVideo.

loadPlayer is our next target.

The most correctly structured way of doing this is by using the following:

  target: ".jacketc",
  width: 600,
  height: 338,
  playerVars: {
    start: 900,
    end: 1200

If you’re okay with that, we’ll update that and get loadPlayer working with that too.


got it here:


The loadPlayer function instead of using two parameters, needs to change to have only the one parameter of opts.
Where containerSelector is used in the loadPlayer function, rename that to
The initPlayer function needs to update opts, with = wrapper.querySelector(".video");
And the rest of the initPlayer function just needs to be videoPlayer.init(opts);


A bunch of errors came up:


I got this far:


Okay, one at a time.

That function still has two parameters, neither of which is entirely correct, when it must only be one.

containerSelector is still being used in the function. This instruction was mistakenly done to the function parameters instead.

This doesn’t seem to have been done at all.

And this hasn’t been done either.

Overall this is a very poor showing, and much more effort is required to get things right.



PlayerVars is in gray?




  function initPlayer(wrapper) {
   videoPlayer.init(opts); = wrapper.querySelector(".video"):

It’s the braces


Okay, back to the list.



This needs to be the first thing in the initPlayer function, not hiding in the videoPlayer code.

Not yet achieved.


I’m messing this up:

  function initPlayer(wrapper) { = wrapper.querySelector(".video");


There should be nothing else after the videoPlayer line. That playerVars should be deleted, as it’s already included in the opts object.



The Grid player is now broken.

TypeError: cover is null


Let’s get that working then. The loadPlayer commands for the grid videos need to be updated in the same way as for the single player.


loadPlayer(".playa", {
  start: 900,
  end: 1200


  target: ".playa",
  playerVars: {
    start: 900,
    end: 1200




We now have width and height coming in from outside of the videoPlayer code, via the init function and through to the addVideo function.

From there, we can now use opts.width or if it’s not defined, 198 instead.

width: opts.width || 198,
height: opts.height || 198,