hatzisn Expert Licensed User Longtime User Sep 4, 2021 #1 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 : Code: Copy function playSound(url) { const audio = new Audio(url); audio.play(); }; I have tested it with this code in the given event: B4X: Copy 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: Copy 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: Copy 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: Sep 4, 2021
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 : Code: Copy function playSound(url) { const audio = new Audio(url); audio.play(); }; I have tested it with this code in the given event: B4X: Copy 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: Copy 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: Copy 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?
hatzisn Expert Licensed User Longtime User Sep 4, 2021 #2 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
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.
hatzisn Expert Licensed User Longtime User Sep 4, 2021 #3 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: Sep 4, 2021 Upvote 0
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?
hatzisn Expert Licensed User Longtime User Sep 4, 2021 #4 I know why you have to click anywhere in the page in order to hear sounds. Here is the answer: Autoplay policy in Chrome | Blog | Chrome for Developers Learn best practices for good user experiences with the new autoplay policies in Chrome. developer.chrome.com Upvote 1
I know why you have to click anywhere in the page in order to hear sounds. Here is the answer: Autoplay policy in Chrome | Blog | Chrome for Developers Learn best practices for good user experiences with the new autoplay policies in Chrome. developer.chrome.com