Audio stops when tab is changed

I’m working on a web based music player i don’t understand why the audio stops as soon as the tab is changed or device screen goes sleep.
My Repl is

The javascript code is in /play/script.js

(If I’m correct)

A lot of websites are like this, it’s probably not an issue with your coding but it’s the way the browser works.


The browser doens’t stops music oj website like Jio Savaan, Spotify etc

Usually big companies have complex services or partnerships (with browsers) that allow them to circunvent those restrictions.
Most web browsers and operating systems have policies on background execution and power savin that are designed to reduce the usage of resources (like battery and CPU) for background tabs or when the screen is off.

You can try to use Media Session along with the Wake Lock API (that you are already using), but it’s not guaranteed that will work.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.