首页 > 解决方案 > Youtube API - 确定是否有人开始/结束观看视频

问题描述

关于YouTube API -- 是否可以确定某人是否已开始观看或已完成观看视频?

标签: phpyoutubeyoutube-api

解决方案


正如您在上面链接的文档中提到的,我建议按照所示执行

   // 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希望它有帮助


推荐阅读