zlacker

[parent] [thread] 3 comments
1. wonger+(OP)[view] [source] 2025-07-25 23:33:29
You should! The browser APIs are straightforward:

  navigator.mediaSession.metadata = new MediaMetadata({
    title: song.name,
    album: song.category,
    artwork: [{src: song.imagePath, type: 'image/jpg'}]
  })

  navigator.mediaSession.setActionHandler('play', player.play)
  navigator.mediaSession.setActionHandler('pause', player.pause)
  navigator.mediaSession.setActionHandler('nexttrack', player.nextTrack)
  navigator.mediaSession.setActionHandler('previoustrack', player.prevTrack)
  // song and player are instances of state
Then you get those native media controls. Even stuff like "hey google, play/pause/skip"
replies(1): >>sltkr+59
2. sltkr+59[view] [source] 2025-07-26 00:57:19
>>wonger+(OP)
Does it work on iOS too?
replies(2): >>wonger+Ge >>master+Xh
◧◩
3. wonger+Ge[view] [source] [discussion] 2025-07-26 02:05:29
>>sltkr+59
MDN says yes as of iOS 15. Don't have an iPhone to double check atm.
◧◩
4. master+Xh[view] [source] [discussion] 2025-07-26 02:48:07
>>sltkr+59
Yes: https://caniuse.com/mdn-api_navigator_mediasession

Try using Spotify's mobile web app for an example. Works great.

[go to top]