// 初始化记忆播放 var videoId = generateVideoId(vid); var savedTime = parseFloat(localStorage.getItem(videoId)) || 0; var shouldResume = savedTime > 10; // 只有大于10秒才恢复 // 创建提示框 $('#player').append('
'); art.on('video:loadeddata', function() { if (shouldResume) { $('#tips').html('X ' + "上次看到 " + formatSeconds(savedTime) + ' 继续'); $('#tips').removeClass("hide"); setTimeout(function() { $('#tips').addClass("hide"); }, 20000); } }); // 每5秒保存一次进度 var saveInterval; art.on('play', function() { saveInterval = setInterval(function() { if (art.currentTime > 0) { localStorage.setItem(videoId, art.currentTime); } }, 5000); }); art.on('pause', function() { clearInterval(saveInterval); }); art.on('video:ended', function() { clearInterval(saveInterval); localStorage.removeItem(videoId); }); // 提示框事件 $('#player').on("click", '#xx', function(e) { art.play(); $('#tips').addClass("hide"); }); $('#player').on("click", '#go', function(e) { art.currentTime = savedTime; art.play(); $('#tips').addClass("hide"); });