How to keep audio running when screen is locked

when the p5.js project runs on a mobile device and the screen dims, audio stops. how can we solve this problem?
Is the answer using WakeLock and keep the screen awake?
Or is there any other workaround to keep audio running when screen gets locked?

Hi @mahatGma. That’s a good question. On my devices when using Processing in Android mode it does run audio in the background. I am also using the Pd4P3 library which may behave differently from your audio API. But first check in your Developer Options you have “Don’t keep activities” turned off. This will definitely kill the audio if it is on.
Otherwise, if that is not the solution you need to create a background service that runs the audio thread. Then the Android OS will continue that service when the screen is locked. There are numerous examples of how to do this so choose a good, modern tutorial. Here is a start: How to play background music in Android app.
This example uses the Android Media Player but in general it works the same way with Processing. Replace your audio code accordingly.