How to implement background music to your app that works consistently

Hi everyone, I’m trying to create an app that has background music when you are on the homepage, stop the music when a display group/popup action happens and restart the music when a user clicks out. I’m having some challenges getting the background music to play consistently so I was thinking maybe someone on this forum might have an idea whats going on.

Currently the set up is that when the page loads the music get played with javascript “document.getElementById(‘soundtrack’).play();” and supposed to pause “document.getElementById(‘soundtrack’).pause();” when a specific group is visible.

The issue is when the page loads sometime the music plays sometime it does not, is there a better way to fire the javascript that I’m missing? Weirdly the javascript always fire when I use bubble preview mode and go step by step.

Anyone with any ideas on whats going on or is there maybe a better way to accomplish this?


The reason sometimes it does not work is that you need to have the user interact with the page first by clicking on something, you can simulate this click with javascript.

This is a browser feature that protects users from hearing unwanted audio :wink:

@nocodeventure thank you for the reply, that makes perfect sense (saw some error reports stating something like that but didn’t understand what it meant).

One follow up question, how would I simulate this click with javascript? Is there a better way in your opinion to accomplish what I’m trying to do? The background music dose’t have to start instantly, I don’t a mind a couple of seconds delay.

Thank you again for the help.

This solution works the best so far: Sound Alerts Request - #27 by sharma.himanshu0608 but stil can’t figure out how to simulate a click or an action (is scroll possible) that would initiate the sound to start playing? Anyone has any ideas or tips?

This topic was automatically closed after 70 days. New replies are no longer allowed.