Prevent Android from closing a progressive web application that plays audio in the background

I wrote a progressive web application that plays music using the web audio API. The usual journey of the user is to start playing music, and then switch to other applications while continuing to listen to music. This works fine until the android decides that other applications require more resources and closes my PWA without warning.

Is there a way to hint at the browser and OS, which, although they are not in the foreground, the user is still using a specific web application? I'm fine so that it can be removed in the background when the music is paused, but not until the user is still listening.

The main browser that interests me is Chrome for Android (although some kind of platform agnostic would be perfect).

+4
source share
1 answer

You can't, today. This is somewhat related to MediaSessions ( https://wicg.imtqy.com/mediasession/ ), but you really need a background application that is not a concept that is still supported by the network (This is also related to ServiceWorkers and web workers, but again not really. It's a really complicated scenario, since such an application has a certain ability to drain the batteries.)

+3
source

Source: https://habr.com/ru/post/1650972/


All Articles