B4J Question WebApp Play Sound

hatzisn

Expert
Licensed User
Longtime User
Good morning everyone,

I have created a test web app with web sockets that will play a sound in given events with this sub in the script section of the webapp in index.html :

Sound in Web App:
        function playSound(url) {
             const audio = new Audio(url);
             audio.play();
            };

I have tested it with this code in the given event:

B4X:
ws.RunFunction("playSound", Array As String("ding.wav"))

It worked perfectly but when I moved the sound in a subfolder named "sounds" in the "www" directory I was not able to play it successfully with this code:

B4X:
ws.RunFunction("playSound", Array As String("sounds/ding.wav"))

Further more when I tried everything I knew to make it work and I did not succeed I took the wav file and moved it back in the "www" directory and deleted the "sounds" subdirectory.

I have changed the code again to:

B4X:
ws.RunFunction("playSound", Array As String("ding.wav"))

Even though I have done this it does not play any sound at all still and I cannot understand why.

Can anyone help?
 
Last edited:

hatzisn

Expert
Licensed User
Longtime User
If I add the code in an click event of a button it works, but if it is added in a timer it works at will.
 
Upvote 0

hatzisn

Expert
Licensed User
Longtime User
I discovered what is going on and this is weird. When the page loads if you do not click anywhere in the page the sound does not play but if you do it plays without any problem. Why is this happening?
 
Last edited:
Upvote 0

hatzisn

Expert
Licensed User
Longtime User
Upvote 1
Top