The problem it fixes
Without Media Session metadata, macOS, iOS and Android fall back to the page title - so hovering a DJ name and playing a 30-second iTunes preview popped up "My Site - Home" in the media popover instead of the song. This file fixes that.
What it does
- title / artist / album pushed into
navigator.mediaSession.metadataon play - 600x600 artwork upgraded automatically from an iTunes-style
artworkUrl100(100x100bb.jpg→600x600bb.jpg) - cleared on pause/ended - or keep the artwork and just flip the state
- no-op safe - no-ops on browsers without the API; every call is try/catch-guarded
Usage
One script tag, one constructor, two calls:
new PreviewMediaSession(audio, { album: 'My Site' })- bind it to your audio elementpms.setTrack(track)- pass iTunes field names (trackName,artistName,artworkUrl100) or generic ones (title,artist,artworkUrl)pms.clear()- when your UI dismisses the player
Frequently asked questions
What does preview-media-session do?
one dependency-free file that makes the OS media popover show the track and cover art instead of the page title when an audio preview plays
Where is the code?
The repository is at https://github.com/bryanhamiltondev/preview-media-session - production-extracted, MIT-licensed where noted in the repo.
Need someone who ships like this?
Bryan Hamilton is a full-stack web engineer with 25+ years in PHP and JavaScript, available immediately for remote, hybrid or on-site roles in the NYC metro area.