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"Browser or native doesn't matter, both have this issue. Heck, this is Google's own software that gets killed: the utility that submits the string to it is still there when I unlock the screen. It's probably just me but I really miss the Android 4 which I had customised to death so it would only run the things I wanted (no bloat): the battery still lasts weeks (the device is >10 years old!) if you don't ask it to do anything because nothing runs in the background. However, when I choose to run an app and don't turn it off before locking the screen, it'd just keep running
But yea, that wouldn't work for the general public
Try using Spotify's mobile web app for an example. Works great.
Meaning the Web App experience is actually better than the native app