我正在使用video.js构建一个自定义视频播放器,我正在尝试创建一个空闲时间功能,在暂停超过1分钟后将视频重定向到主页。最简单的方法是什么?
myPlayer.on("pause", function() {
window.location = "../index.html";
});
答案 0 :(得分:3)
你大部分都在那里,你只需要使用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);
});