Sound URL in HTMLViewer not working

I have a WebApp containing an HTMLViewer. If I set the URL of this HTMLViewer to a web site link that plays a sound it doesn’t make the sound, but displays an error. Other URLs work OK. Is there a workaround?

What’s the error?

My mistake. When I was trying to do a LoadPage with JavaScript that autoplayed the sound it gave an error.

My issue here is that the sound auto-plays in Safari just by clicking the link, but in the HTMLViewer it just displays the Audio controls and doesn’t auto-play the sound:

Ah, so that’s a security feature of the browser. The htmlviewer in the web framework is actually an “iframe” and it’s not uncommon that they contain ads or other obnoxious content. The browser is trying to protect you from that.

All my old methods of playing a sound automatically in a WebApp are now failing. I just want to play a sound (and flash the number) when a new user registers (via a timer). I have the flash working via a WebStyle, but is there any way to play a sound?

Browsers have gotten more and more picky about letting sites spontaneously play sounds without some sort of user interaction first, that is, within the same event loop. I suspect that if the playing of the sound was directly triggered by the user pressing the button and didn’t require the round-trip to the server, that you might have more luck. That would require coding all of that in JavaScript unfortunately.

I have tried all the JavaScript options I could find and couldn’t get any of them to work.

In this WebApp the company wants a PC set aside as an unattended Dashboard continuously displaying the number of registrations, and flashing/sounding when the number increases, so clicking a button is not an option.

My web page (written in PHP/Javascript) needs to play an alarm sound but it never will for users with a mobile browser. Users just don’t understand why - they want to keep the mobile browser open and get the alarm horn just like they do on their computer. I’ve considered making a mobile app but can’t figure out how to get the alarms when the app is in the background or the phone is locked. I also don’t want to have to make an Android version.

But anyway, PC browsers can still automatically play a sound. The method I currently use looks like this in PHP using an html5 audio tag.

if ($myalarm) { echo "<audio autoplay loop>"; echo "<source src='webalarm.ogg'>"; echo "<source src='webalarm.mp3'>"; echo "<source src='webalarm.m4a'>"; echo "<source src='webalarm.wav'>"; echo "</audio>"; }

I’m not sure how you would get this to work in a WebApp.

Try this:

  1. Add a constant to a web page (kScript As String) and set its text to this:

var audio = document.createElement('audio'); audio.src = '';

  1. Add a button to the page, set Visible = OFF and put this code in the Open event:

Run the project and the mp3 should start playing automatically. It worked for me in both Safari and Chrome on macOS.

I cannot get either to work on my Mac here. Here is the app I built according to Paul’s instructions — please show me where I have gone wrong.

Weird. Yours did not work for me either. And yet it looked exactly the same as my project. I ended up copying my kScript constant to your project and now yours works. So maybe something with CR/LF in the constant?

Anyway, here’s a link to what is working for me: PlaySound

I can get it to work in Chrome, but not Safari. In the Sierra Safari settings I have allowed playing of sound for all web sites.

It’s working everywhere now, and with a sound URL as a variable. Thanks Paul.