Website: Media Session API — background playback + lock screen controls

Shows album art, title, artist on lock screen. Play/pause/next/prev
from notification. Audio continues when phone screen is off.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-04 13:32:34 -04:00
parent d53a2c80c1
commit 1a1062edeb
+19
View File
@@ -559,6 +559,25 @@ function playTrack(index) {
document.getElementById('player-title').textContent = t.title;
document.getElementById('play-btn').textContent = '⏸';
document.title = `${t.title} — Interpretations`;
// Media Session API — background playback + lock screen controls
if ('mediaSession' in navigator) {
navigator.mediaSession.metadata = new MediaMetadata({
title: t.title,
artist: 'Infinite State',
album: 'Interpretations',
artwork: [
{ src: 'cover.png', sizes: '1024x1024', type: 'image/png' }
]
});
navigator.mediaSession.setActionHandler('play', () => togglePlay());
navigator.mediaSession.setActionHandler('pause', () => togglePlay());
navigator.mediaSession.setActionHandler('previoustrack', () => prevTrack());
navigator.mediaSession.setActionHandler('nexttrack', () => nextTrack());
navigator.mediaSession.setActionHandler('seekto', (details) => {
audio.currentTime = details.seekTime;
});
}
}
function togglePlay() {