Prevent Android from closing a Progressive Web App playing audio in the background
Asked Answered
S

2

11

I've written a progressive web app which plays music using the Web Audio API. A common user journey is to start the music playing, then change to other apps whilst still listening to the music. This works fine for a while, until android decides that it needs more resources for the other apps and closes down my PWA without warning.

Is there a way to hint to the browser and OS that despite not being in the foreground, the user is still using a particular web app? I'm fine for it to be tidied up in the background when the music is paused, but not whilst the user is still listening to something.

The main browser I'm interested in is Chrome for Android (though something platform agnostic would be ideal).

Stamm answered 11/8, 2016 at 22:47 Comment(4)
Did you ever find a solution for this? – Fiden
No solution, but I've found upgrading to a phone with more resources means the PWA stays open longer than before. Probably not useful if you're building something with multiple users though πŸ˜‚ – Stamm
I discovered an interesting workaround for my issue... Chrome will continue to play looped audio in the background only if service workers are not used, so I just removed the service worker and my audio continues to play. – Fiden
@BruceHamilton interesting, I will try that when I get the chance – Deaconess
T
4

You can't, today. This is somewhat related to MediaSessions (https://wicg.github.io/mediasession/), but you really need a background app, which is not a concept that's yet supported by the web. (It's related, also, to ServiceWorkers and Web Workers, but again, not precisely. It's really a difficult scenario, as such an app has a definite ability to drain batteries.)

Threadfin answered 11/8, 2016 at 23:17 Comment(2)
has anything changed? – Creatural
has anything changed> – Cologarithm
D
1

I have created a bug for this Chrome bug

If you have steps to reproduce, please comment on the bug

Deaconess answered 17/9, 2018 at 15:46 Comment(0)

© 2022 - 2024 β€” McMap. All rights reserved.