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

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

本文关键字:重定向 新页面 1分钟 暂停 视频      更新时间:2023-09-26

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

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

您已经完成了大部分工作,只需要使用setTimeout(),请参阅此处了解更多信息。您需要确保在再次单击播放后取消计时器。

代码

//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);
});