From dec607e6ae4c0cd0647bcdfdd3005ba6ee144f8c Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Sat, 4 Apr 2026 13:36:49 -0400 Subject: [PATCH] Website: iOS background playback fixes + lock screen seek bar Co-Authored-By: Claude Opus 4.6 (1M context) --- site/index.html | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/site/index.html b/site/index.html index 53461f2..6ba346c 100644 --- a/site/index.html +++ b/site/index.html @@ -451,6 +451,10 @@ const TRACKS = [ const audio = new Audio(); audio.crossOrigin = 'anonymous'; +audio.preload = 'auto'; +// iOS needs this attribute for background playback +audio.setAttribute('playsinline', ''); +audio.setAttribute('webkit-playsinline', ''); let currentTrack = -1; let isPlaying = false; @@ -632,12 +636,20 @@ audio.addEventListener('ended', () => { } }); -// Progress updates +// Progress updates + media session position audio.addEventListener('timeupdate', () => { document.getElementById('time-current').textContent = formatTime(audio.currentTime); document.getElementById('time-total').textContent = formatTime(audio.duration); const pct = (audio.currentTime / audio.duration) * 100; document.getElementById('progress-fill').style.width = pct + '%'; + // Update lock screen seek bar + if ('mediaSession' in navigator && !isNaN(audio.duration)) { + navigator.mediaSession.setPositionState({ + duration: audio.duration, + playbackRate: 1, + position: audio.currentTime + }); + } }); // Load durations