Can Javascript detect when an embedded Youtube video has ended?

前端 未结 2 2078
遥遥无期
遥遥无期 2021-01-27 04:25

I have a div containing a video. The background of the div features a fake \"play\" button, which I\'ve designed to use as the play button instead of Youtube\'s standard video

2条回答
  •  甜味超标
    2021-01-27 04:49

    Take a look in the API, it seems there is events.

    player.addEventListener('onStateChange', function(e) {
       if (e.data === 0) {
         // If state is 0 (ended), do something
       }
    });
    
    • API provided by Google.
    • Events API
    • Embedding via JavaScript

    Also, on the side note:

    It looks like your YouTube video needs to be embed via JavaScript for events. To do so,

提交回复
热议问题