paulirish / lite-youtube-embed

A faster youtube embed.
https://paulirish.github.io/lite-youtube-embed/
Other
5.6k stars 259 forks source link

I am using lite youtube embed and I want to get onStateChange player.getPlayerState(): #174

Open FrostBite70 opened 3 months ago

FrostBite70 commented 3 months ago

I am new in studying and learning javascript, can you add a bit of changes to the code for the onstatechange, I checked and tried to modify the code, trying to add it but I fail. The code I tried to make with getPlayerState() only triggers the chosen video id to play but not to get the values stated in: https://developers.google.com/youtube/iframe_api_reference#getPlayerState 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 } }); `