我正在使用 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);
});
关于javascript - 视频暂停超过1分钟后重定向到新页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29264754/