Best practice for background music/ soundtrack

I’d like to create a soundtrack for the app I’m working on but struggling on getting the background music play consistently… what would be the best way to accomplish this? I’m especially curious if someone would have advice on how to easily let users toggle background music off/on in their user profile. Any advice that can get me started to towards the right direction would be much appreciated!

Update: I’m able to get it to work with a simple html5 audio player and javascript based on this thread! However, I’m struggling with how to

a, Get the music to pause when the user is not active on the screen (for example on a different tab or different app). I tried adding a workflow that pauses the audio when the page is not visible but it still keeps playing in the background. Does anyone have an idea on how to get this accomplished?

b, I’m realizing it would probably be a good idea to set up a toggle option for users to be able to turn audio off and on. I’m assuming that workflow playing the audio needs to include a state with a yes/no function to best accomplish this. I’m I correct in my assumption?

Would appreciate any tips or advice!

Still struggling with this and need to showcase the app this afternoon does anyone have any tips?