I have a responsive section with a youtube video, I would like to capture the click event in the youtube video play, how would I capture it? ie send an alert for example, as soon as you play the video on youtube.
I have a responsive section with a youtube video, I would like to capture the click event in the youtube video play, how would I capture it? ie send an alert for example, as soon as you play the video on youtube.
You can use the YouTube Javascript API ( link )
Using the callback onStateChange
, you get what type of video status.
Events
onStateChange This event is triggered whenever the player state changes. The value that the API passes to its listener function events will specify an integer that corresponds to the new state of the player. The 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 (-1) unstarted event. When the video is displayed and ready to play, the player will stream a video event indicated video cued (5). In your code, you can specify values of integers or you can use one of the following variables namespaced:
YT.PlayerState.ENDED YT.PlayerState.PLAYING YT.PlayerState.PAUSED YT.PlayerState.BUFFERING YT.PlayerState.CUED