Quantcast
Channel: Active questions tagged youtube-api - Stack Overflow
Viewing all articles
Browse latest Browse all 3831

Anyone around Good at both Javascript and Youtube api?, I am using lite-youtube js and I am confused in adding an eventlistener for onStateChange

$
0
0

I am new in studying and learning javascript and I am using a lite youtube js from paulirish from githubhttps://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 valueif (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!


Viewing all articles
Browse latest Browse all 3831

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>