mirror of
https://github.com/kennethreitz/interpretations.git
synced 2026-06-05 23:00:19 +00:00
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:
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user