I am new in studying and learning javascript and I am using a lite youtube js from paulirish from github https://github.com/paulirish/lite-youtube-embed

I want to get onstatechange and addeventlistener after the video ends. I found some codes here in stackoverflow about the same problem, I tried their codes but it doesn't seem to work because lite-youtube is a bit different in youtube api's coding. I am confused in how to make this work and get onStateChange to add an eventlistener.

I have tried to make my own modification in his javascript but I don't have the knowledge and experience in using both js and youtube api. I have been trying to get the onstate value with onStateChange player.getPlayerState() with my own codes but I fail:

async function getPlayerState(number, id) { let num = document.querySelector(lite-youtube[id='${id}']`);
let player = await num.getYTPlayer();
player?.getPlayerState(number, true);
}

playlist.addEventListener('click', () => {
this.getPlayerState(1, '1') // the string inside works and plays the specific video id but it does not get the PlayerState value
if (this.getPlayerState(0, '1')) {
this.getPlayerState(1, '2') //<=this always trigger the specific video id but it plays no matter what is changed on the ifcondition
}
});

The link to Youtube api I am saying is here: https://developers.google.com/youtube/iframe_api_reference#getPlayerState

Thank You Very Much in Advance to Anyone who will be able to Help!

0

There are 0 best solutions below