视频暂停超过 1 分钟后重定向到新页面

Redirect to new page after video is paused for more than 1 minute

我正在使用 video.js 构建一个自定义视频播放器,我正在尝试创建一个空闲时间功能,在暂停超过 1 分钟后将视频重定向到主页。最简单的方法是什么?

myPlayer.on("pause", function() {
  window.location = "../index.html";
});

您已经完成了大部分工作,您只需要使用 setTimeout(),有关详细信息,请参阅 here。您需要确保在再次点击播放后取消计时器。

代码

//Global timer object, needed so we can clear it
var timer = null;

myPlayer.on("pause", function() 
{
  //Set the time once the player is paused. Note: 60000 is 1 minute
  timer = setTimeout(function(){window.location = "../index.html"}, 60000);
});

myPlayer.on("play", function() 
{
  //If the user clicks play stop the timer
  //You may need to use this code in other events
  clearTimeout(timer);
});