Fix progress bar seek pausing playback + add persistent mini-player
- video-player: add userSeeking flag so mid-seek pause events are suppressed; force-resume on 'seeked' if video was playing before seek; guard player click handler against progCont clicks; e.preventDefault() on touchend to stop synthetic click toggling play - audio-player: apply identical seek fixes (same four changes) - app layout: add floating mini-player that saves video state to sessionStorage when bottom nav is tapped while a video is playing, then restores playback on the next page via a floating overlay Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
This commit is contained in:
1 parent
615e7efd7c
commit
d1441b213a
3 files changed
+264
-13
No files matched your search
@@ -374,8 +374,10 @@ const barsBtn = document.getElementById('ytpBarsBtn');
|
||||
const animCanvas = document.getElementById('audioAnimCanvas');
|
||||
|
||||
const NEXT_URL = @json($nextUrl ?? null);
|
||||
let hideTimer = null;
|
||||
let isDragging = false;
|
||||
let hideTimer = null;
|
||||
let isDragging = false;
|
||||
let userSeeking = false;
|
||||
let wasPlayingBeforeSeek = false;
|
||||
|
||||
// ── Helpers ──────────────────────────────────────────────────
|
||||
function fmt(s) {
|
||||
@@ -422,6 +424,7 @@ function togglePlay() {
|
||||
playBtn.addEventListener('click', e => { e.stopPropagation(); togglePlay(); showControls(); });
|
||||
player.addEventListener('click', e => {
|
||||
if (settingsPanel.contains(e.target) || settingsBtn === e.target) return;
|
||||
if (progCont.contains(e.target)) return;
|
||||
togglePlay();
|
||||
});
|
||||
player.addEventListener('mousemove', showControls);
|
||||
@@ -447,6 +450,8 @@ volRange.addEventListener('click', e => e.stopPropagation());
|
||||
// ── Progress bar ─────────────────────────────────────────────
|
||||
function seekTo(pct) {
|
||||
if (!audio.duration) return;
|
||||
if (!userSeeking) wasPlayingBeforeSeek = !audio.paused;
|
||||
userSeeking = true;
|
||||
audio.currentTime = Math.max(0, Math.min(1, pct)) * audio.duration;
|
||||
updateProgress();
|
||||
}
|
||||
@@ -468,7 +473,7 @@ document.addEventListener('mousemove', e => { if (isDragging) seekTo(progressPct
|
||||
document.addEventListener('mouseup', () => { if (isDragging) { isDragging = false; progBar.classList.remove('dragging'); } });
|
||||
progCont.addEventListener('touchstart', e => { isDragging = true; progBar.classList.add('dragging'); seekTo(progressPct(e.touches[0].clientX)); }, { passive: true });
|
||||
progCont.addEventListener('touchmove', e => { if (isDragging) seekTo(progressPct(e.touches[0].clientX)); }, { passive: true });
|
||||
progCont.addEventListener('touchend', () => { isDragging = false; progBar.classList.remove('dragging'); });
|
||||
progCont.addEventListener('touchend', e => { e.preventDefault(); isDragging = false; progBar.classList.remove('dragging'); });
|
||||
|
||||
// ── Settings / Speed ─────────────────────────────────────────
|
||||
settingsBtn.addEventListener('click', e => {
|
||||
@@ -540,7 +545,17 @@ document.addEventListener('keydown', e => {
|
||||
|
||||
// ── Audio events ─────────────────────────────────────────────
|
||||
audio.addEventListener('play', () => { updatePlayIcon(); startBars(); showControls(); largePlay.classList.remove('visible'); requestWakeLock(); });
|
||||
audio.addEventListener('pause', () => { updatePlayIcon(); stopBars(); showControls(); largePlay.classList.add('visible'); clearTimeout(hideTimer); releaseWakeLock(); });
|
||||
audio.addEventListener('pause', () => {
|
||||
if (userSeeking) return; // suppress mid-seek pause events
|
||||
updatePlayIcon(); stopBars(); showControls(); largePlay.classList.add('visible'); clearTimeout(hideTimer); releaseWakeLock();
|
||||
});
|
||||
audio.addEventListener('seeked', () => {
|
||||
userSeeking = false;
|
||||
if (wasPlayingBeforeSeek) {
|
||||
if (audio.paused) audio.play().catch(() => {});
|
||||
largePlay.classList.remove('visible');
|
||||
}
|
||||
});
|
||||
audio.addEventListener('timeupdate', updateProgress);
|
||||
audio.addEventListener('durationchange', () => { timeDur.textContent = fmt(audio.duration); });
|
||||
audio.addEventListener('ended', () => { releaseWakeLock(); if (NEXT_URL) window.location.href = NEXT_URL; });
|
||||
|
||||
Reference in new issue
Block a user