tip.querySelector('.resume-btn').addEventListener('click', () => { art.currentTime = savedTime; tip.style.display = 'none'; art.play(); }); // 从头播放按钮事件 tip.querySelector('.cancel-btn').addEventListener('click', () => { localStorage.removeItem(videoId); tip.style.display = 'none'; art.currentTime = 0; art.play(); }); return tip; } // 初始化播放器事件 art.on('ready', () => { initColorMarquee(); // 初始化记忆播放提示 const memoryTip = initMemoryPlaybackTip(); // 如果有记忆位置且大于10秒,显示提示 if (shouldResume) { memoryTip.style.display = 'block'; // 10秒后自动隐藏提示 setTimeout(() => { memoryTip.style.display = 'none'; }, 10000); } // 尝试自动播放 art.play().catch(e => { art.notice.show = '点击播放按钮开始播放'; }); }); // 视频播放时保存进度 let saveInterval; art.on('play', () => { // 每5秒保存一次进度 saveInterval = setInterval(() => { if (art.currentTime > 0) { localStorage.setItem(videoId, art.currentTime); } }, 5000); }); // 视频暂停时清除保存定时器 art.on('pause', () => { clearInterval(saveInterval); }); // 视频结束时清除记忆 art.on('video:ended', () => { clearInterval(saveInterval); localStorage.removeItem(videoId); }); // 页面卸载前保存当前进度 window.addEventListener('beforeunload', () => { if (art.currentTime > 0 && !art.paused) { localStorage.setItem(videoId, art.currentTime); } }); } // 初始化播放器 document.addEventListener('DOMContentLoaded', initPlayer);