Capture youtube play click event

Asked

Viewed 257 times

3

I have a responsive Séction with a youtube video, would you like to capture the click on play event of the youtube video, could you capture? ie, send an Alert for example, once play is given on youtube video.

  • Arnaldo, could post the code snippet so we can help you?

1 answer

1

You can use the Youtube Javascript API (https://developers.google.com/youtube/js_api_reference?hl=pt-br)

Using the callback onStateChange, you get what kind of video status.

Events

onStateChange This event is triggered whenever the player’s state is changed. The value the API passes to its system function events will specify an integer that corresponds to the new state player. 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 first loads a video, it streams an unstarted (-1) uninitiated 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 integer numbers 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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.