Answer the question
In order to leave comments, you need to log in
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() {
...
})
$(document).ready(function() {
// Сюда
})
player.getVolume()
$(document).ready(function() {
console.log(player.getVolume()); // И мне бы вывело значение, а не "TypeError: player is undefined"
})
Answer the question
In order to leave comments, you need to log in
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() {}
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 questionAsk a Question
731 491 924 answers to any question