For Android, it sounds like you are needing an Android Foreground Service. Capawesome has a simple plugin for it - Capacitor Android Foreground Service Plugin - Capawesome. If that doesn’t work, it’s not too hard to create your own as a local Capacitor plugin.
For iOS, I am not that familiar. For an audio plugin I created, I just had to check a box in XCode saying the app requires background mode.