E
E
Egor Astreiko2018-06-12 02:15:15
YouTube
Egor Astreiko, 2018-06-12 02:15:15

How to correctly pass the player variable?

Good night everyone, I started to be stupid, I have a js file:

// Функции YouTube Api
var player;
// Инициализация плеера
function onYouTubeIframeAPIReady() {
  player = new YT.Player("video", {
    height: "",
    width: "",
    videoId: "",
    playerVars: {
      "controls": 0,
      "rel": 0,
      "disablekb": 0,
      "html5": 1, 
      "iv_load_policy": 3,
      "showinfo": 0,
      "fs": 0
    },
    events: {
      onReady: onPlayerReady,
      onStateChange: onPlayerStateChange
    }
  });
}

function onPlayerReady() {}

function onPlayerStateChange() {}

$(document).ready(function() {
...
})

The question is very simple, how do I pass the value of the variable player
$(document).ready(function() {
// Сюда
})

so that I could, for example, get sound through a string. player.getVolume()

So that the end result would be like this:
$(document).ready(function() {
       console.log(player.getVolume()); // И мне бы вывело значение, а не "TypeError: player is undefined"
})


Thanks in advance.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Egor Astreiko, 2018-06-13
@Egor1324

I solved the problem by adding all the actions with the player to this function , which is called after the player is initialized function onPlayerReady() {}

A
Alexey Ukolov, 2018-06-12
@alexey-m-ukolov

In order not to repeat the same thing for the thousandth time, here is a link to the answer: How to return a json object in nodeJs?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question