Youtube API-确定某人是否已经开始/结束观看视频

时间:2019-04-11 10:58:01

标签: php youtube youtube-api

关于YouTube API-是否可以确定某人是开始观看视频还是结束观看视频?

1 个答案:

答案 0 :(得分:0)

如您在上面的文档linked中所述,我建议遵循所示的实现方式

   // 4. The API will call this function when the video player is ready.
  function onPlayerReady(event) {
    event.target.playVideo();
  }

  // 5. The API calls this function when the player's state changes.
  //    The function indicates that when playing a video (state=1),
  //    the player should play for six seconds and then stop.
  var done = false;
  function onPlayerStateChange(event) {
    if (event.data == YT.PlayerState.PLAYING && !done) {
      setTimeout(stopVideo, 6000);
      done = true;
    }
  }

一些更有用的链接herehere希望对您有帮助