fix: Scrub lag fix and Volume control for Audiobooks

This commit is contained in:
Honey committed 2026-05-03 17:20:02 +02:00
1 parent 4b07203082
commit 7744ae85db
4 files changed
+37 -9

No files matched your search

+1 -1
View File
@@ -149,7 +149,7 @@ window.addEventListener('load', () => {
}
});
S.audio.volume = 0.65;
S.audio.volume = 0.5;
// Re-register MediaSession handlers when returning from background/screen-off/flip
document.addEventListener('visibilitychange', () => {
+23 -6
View File
@@ -213,8 +213,16 @@ export function updateProgress() {
export function seekTo(e) {
const bar = document.getElementById('progress-bar');
if (!bar || !S.audio.duration) return;
const rect = bar.getBoundingClientRect();
S.audio.currentTime = ((e.clientX - rect.left) / rect.width) * S.audio.duration;
const pos = Math.max(0, Math.min(1, (e.clientX - rect.left) / rect.width));
const fill = document.getElementById('progress-fill');
if (fill) { fill.style.transition = 'none'; fill.style.width = (pos * 100) + '%'; }
S.audio.currentTime = pos * S.audio.duration;
S._scrubbing = true;
const done = () => { S._scrubbing = false; requestAnimationFrame(() => { if (fill) fill.style.transition = ''; }); };
S.audio.addEventListener('seeked', done, { once: true });
setTimeout(done, 1500);
}
export function initProgressScrub() {
@@ -236,14 +244,15 @@ function _initBarScrub(bar, fill, onMove) {
function startScrub(pos) { S._scrubbing=true; fill.style.transition='none'; fill.style.width=(pos*100)+'%'; onMove(pos); }
function moveScrub(pos) { fill.style.width=(pos*100)+'%'; onMove(pos); }
function endScrub(pos) {
fill.style.transition='';
fill.style.width = (pos * 100) + '%'; // pin visual position before re-enabling transition
if(S.audio.duration) {
S.audio.currentTime = pos * S.audio.duration;
// Keep _scrubbing=true until seek completes so timeupdate can't snap bar back
S.audio.addEventListener('seeked', () => { S._scrubbing = false; }, { once: true });
setTimeout(() => { S._scrubbing = false; }, 1500); // fallback if seeked never fires
const done = () => { S._scrubbing = false; requestAnimationFrame(() => { fill.style.transition = ''; }); };
S.audio.addEventListener('seeked', done, { once: true });
setTimeout(done, 1500); // fallback if seeked never fires
} else {
S._scrubbing = false;
fill.style.transition = '';
}
}
bar.addEventListener('touchstart', e => { startScrub(getPos(e.touches[0].clientX)); e.stopPropagation(); }, {passive:true});
@@ -258,7 +267,15 @@ function _initBarScrub(bar, fill, onMove) {
});
}
export function setVolume(v) { S.audio.volume = v/100; S.previewAudio.volume = v/100; }
export function setVolume(v) {
const vol = v / 100;
S.audio.volume = vol;
S.previewAudio.volume = vol;
const absAudio = document.getElementById('abs-audio');
if (absAudio) absAudio.volume = vol;
// sync all volume sliders
document.querySelectorAll('.volume-slider-sync').forEach(el => { el.value = v; });
}
// ─── MEDIA SESSION ───
export function updateMediaSession(s) {