zlacker

[return to "Do not download the app, use the website"]
1. rickca+T7[view] [source] 2025-07-25 23:04:53
>>foxfir+(OP)
I dream of developing mobile sites that can play audio with the screen off and use the same media controls as apps (think: music player apps while driving). A lot of the things that make mobile sites second class is the lack of screen-off functionality.
◧◩
2. wonger+pb[view] [source] 2025-07-25 23:33:29
>>rickca+T7
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"
[go to top]