I want to run a function called stopSlide whenever someone clicks the ‘play’ button on an embedded youtube video. Or even getting the function to run when they click anywhere inside the embedded video would work fine for me right now.
How can I do this?
There is a YouTube JavaScript API that provides event callbacks.
There is, unfortunately, no way to directly detect a click event (at least I am not aware of any). You can, however, detect changes in the player state for which you can use
onStateChange.First, you will need to enable the JS API in the player by embedding it by using a special URL:
Then you need to create an event handler function:
Lastly, you need to make sure that the handler gets called whenever the state of the movie changes: