# Sound URL in HTMLViewer not working

**URL:** <https://forum.xojo.com/t/sound-url-in-htmlviewer-not-working/38838>\
**Category:** Web\
**Created:** [July 24, 2017, 9:52am UTC](https://forum.xojo.com/t/sound-url-in-htmlviewer-not-working/38838 "2017-07-24T09:52:39Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_Cox](https://forum.xojo.com/user_avatar/forum.xojo.com/david_cox/32/227_2.png) [@David\_Cox](https://forum.xojo.com/u/David_Cox)\
**Post date:** [July 24, 2017, 9:52am UTC](https://forum.xojo.com/t/sound-url-in-htmlviewer-not-working/38838/1 "2017-07-24T09:52:39Z")

</div>

I have a WebApp containing an HTMLViewer. If I set the URL of this HTMLViewer to a web site link that [plays a sound](http://www.webappdevelopments.com/sounds/ZoomAway.mp3) it doesn’t make the sound, but displays an error. Other URLs work OK. Is there a workaround?

---

<div class="post-metadata">

**Author:** ![Greg\_O\_Lone](https://forum.xojo.com/user_avatar/forum.xojo.com/greg_o_lone/32/49_2.png) [@Greg\_O\_Lone](https://forum.xojo.com/u/Greg_O_Lone)\
**Post date:** [July 24, 2017, 11:18am UTC](https://forum.xojo.com/t/sound-url-in-htmlviewer-not-working/38838/2 "2017-07-24T11:18:19Z")

</div>

What’s the error?

---

<div class="post-metadata">

**Author:** ![David\_Cox](https://forum.xojo.com/user_avatar/forum.xojo.com/david_cox/32/227_2.png) [@David\_Cox](https://forum.xojo.com/u/David_Cox)\
**Post date:** [July 24, 2017, 11:39am UTC](https://forum.xojo.com/t/sound-url-in-htmlviewer-not-working/38838/3 "2017-07-24T11:39:43Z")

</div>

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:  
 ![](http://www.webappdevelopments.com/downloads/Xojo006.png)

---

<div class="post-metadata">

**Author:** ![Greg\_O\_Lone](https://forum.xojo.com/user_avatar/forum.xojo.com/greg_o_lone/32/49_2.png) [@Greg\_O\_Lone](https://forum.xojo.com/u/Greg_O_Lone)\
**Post date:** [July 24, 2017, 12:10pm UTC](https://forum.xojo.com/t/sound-url-in-htmlviewer-not-working/38838/4 "2017-07-24T12:10:11Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![David\_Cox](https://forum.xojo.com/user_avatar/forum.xojo.com/david_cox/32/227_2.png) [@David\_Cox](https://forum.xojo.com/u/David_Cox)\
**Post date:** [July 24, 2017, 12:13pm UTC](https://forum.xojo.com/t/sound-url-in-htmlviewer-not-working/38838/5 "2017-07-24T12:13:13Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Greg\_O\_Lone](https://forum.xojo.com/user_avatar/forum.xojo.com/greg_o_lone/32/49_2.png) [@Greg\_O\_Lone](https://forum.xojo.com/u/Greg_O_Lone)\
**Post date:** [July 25, 2017, 10:14am UTC](https://forum.xojo.com/t/sound-url-in-htmlviewer-not-working/38838/6 "2017-07-25T10:14:20Z")

</div>

> [@341876:@David Cox](#):
>
> 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.

---

<div class="post-metadata">

**Author:** ![David\_Cox](https://forum.xojo.com/user_avatar/forum.xojo.com/david_cox/32/227_2.png) [@David\_Cox](https://forum.xojo.com/u/David_Cox)\
**Post date:** [July 25, 2017, 10:23am UTC](https://forum.xojo.com/t/sound-url-in-htmlviewer-not-working/38838/7 "2017-07-25T10:23:57Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Richard\_White](https://forum.xojo.com/user_avatar/forum.xojo.com/richard_white/32/651_2.png) [@Richard\_White](https://forum.xojo.com/u/Richard_White)\
**Post date:** [July 25, 2017, 12:10pm UTC](https://forum.xojo.com/t/sound-url-in-htmlviewer-not-working/38838/8 "2017-07-25T12:10:56Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Paul\_Lefebvre](https://forum.xojo.com/user_avatar/forum.xojo.com/paul_lefebvre/32/3152_2.png) [@Paul\_Lefebvre](https://forum.xojo.com/u/Paul_Lefebvre)\
**Post date:** [July 25, 2017, 2:03pm UTC](https://forum.xojo.com/t/sound-url-in-htmlviewer-not-working/38838/9 "2017-07-25T14:03:06Z")

</div>

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 = 'http://www.archive.org/download/Stockfinster.-DeadLinesutemos025/01_Push_Push.mp3'
audio.play();`

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

```auto
Me.ExecuteJavaScript(kScript)
```

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

---

<div class="post-metadata">

**Author:** ![David\_Cox](https://forum.xojo.com/user_avatar/forum.xojo.com/david_cox/32/227_2.png) [@David\_Cox](https://forum.xojo.com/u/David_Cox)\
**Post date:** [July 25, 2017, 2:19pm UTC](https://forum.xojo.com/t/sound-url-in-htmlviewer-not-working/38838/10 "2017-07-25T14:19:27Z")

</div>

I cannot get either to work on my Mac here. Here is the [app I built](http://www.webappdevelopments.com/downloads/PlaySound.zip) according to Paul’s instructions  please show me where I have gone wrong.

---

<div class="post-metadata">

**Author:** ![Paul\_Lefebvre](https://forum.xojo.com/user_avatar/forum.xojo.com/paul_lefebvre/32/3152_2.png) [@Paul\_Lefebvre](https://forum.xojo.com/u/Paul_Lefebvre)\
**Post date:** [July 25, 2017, 2:36pm UTC](https://forum.xojo.com/t/sound-url-in-htmlviewer-not-working/38838/11 "2017-07-25T14:36:34Z")

</div>

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](https://www.dropbox.com/s/9hd0f8iti5o8jef/Play%20Sound2.xojo_binary_project.zip?dl=0)

---

<div class="post-metadata">

**Author:** ![David\_Cox](https://forum.xojo.com/user_avatar/forum.xojo.com/david_cox/32/227_2.png) [@David\_Cox](https://forum.xojo.com/u/David_Cox)\
**Post date:** [July 25, 2017, 3:01pm UTC](https://forum.xojo.com/t/sound-url-in-htmlviewer-not-working/38838/12 "2017-07-25T15:01:38Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![David\_Cox](https://forum.xojo.com/user_avatar/forum.xojo.com/david_cox/32/227_2.png) [@David\_Cox](https://forum.xojo.com/u/David_Cox)\
**Post date:** [July 25, 2017, 3:56pm UTC](https://forum.xojo.com/t/sound-url-in-htmlviewer-not-working/38838/13 "2017-07-25T15:56:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://forum.xojo.com/uploads/default/original/1X/455b4dcc0e61630e9f81940004ddffa49c432a46.png) [@system](https://forum.xojo.com/u/system)\
**Post date:** [October 29, 2020, 6:51pm UTC](https://forum.xojo.com/t/sound-url-in-htmlviewer-not-working/38838/14 "2020-10-29T18:51:25Z")

</div>


