html5 – Capture youtube click on play event

Question:

I have a responsive section with a youtube video, I would like to capture the click no play event of the youtube video, would I be able to capture it? that is, send an alert, for example, as soon as play is given on the youtube video.

Answer:

You can use the YouTube Javascript API ( https://developers.google.com/youtube/js_api_reference?hl=en )

Using the onStateChange callback, you get what the video's status type is.

Events

onStateChange This event is fired whenever the state of the player changes. The value that the API passes to your event listener function will specify an integer that corresponds to the new player state. Possible values ​​are:

 -1 (não iniciado) 0 (encerrado) 1 (em reprodução) 2 (em pausa) 3 (armazenando em buffer) 5 (vídeo indicado).

When the player loads a video for the first time, it broadcasts an unstarted unstarted event (-1). When the video is tagged and ready to play, the player will broadcast a video tagged event video cued (5). In your code, you can specify integer values ​​or you can use one of the following namespaced variables:

 YT.PlayerState.ENDED YT.PlayerState.PLAYING YT.PlayerState.PAUSED YT.PlayerState.BUFFERING YT.PlayerState.CUED
Scroll to Top
AllEscort