OSX Safari play sound on load


#1

Hi there,

I’m in the middle of trying to get an audiofile to play as soon as my Hype project loads. For the life of me I cannot get it to work in Safari on MAC OS X. I know that mobile Safari won’t autoplay anything, but I’ve tried many different approaches to get it working on MAC OS X Safari browser.

That said, there is actually one single thing that makes the sound play on load: If I use the “Play sound…” action under the “On Scene Load” panel in Hype. The reason why I’d rather not us this approach is, that this way I can’t seem to find a way to target that particular sound to make it stop, so it won’t play on top of another sound.

Does description of the problem make sense? Can anyone tell me why the “Play sound…” action works, and none of my other approaches(javascript, embedded HTML5 etc) won’t?

PS. All the soundbites I use works fine, and I can stop (well, pause) them and everything…just not automatically on project load


#2

@Sune

It sounds like You are conversant with audio tags and playing~pausing them with JavaScript, so I’m just going to get right to the key element:

Trigger your sound to play ~ mySound.play(); ~ via the “On Scene Load” handler in your opening scene…
where “mySound” is a variable set to the ID of the audio (tag) you wish to play.


#3

Thx for taking the time, JimScott :slight_smile:

I’ve already tried this, but it won’t work on the first “On Load Scene”. At least not in Safari. I’ve tried using

mySound =new Audio(’${resourcesFolderName}/audiofile.mp3’);
mySound.play();

This works all over my Hypeproject except on loading the first scene (and i’ve checked the variable, and it’s fine when it gets initiated)

I’ve also tried putting an tag inside an elements inner html and using it’s id as you suggested. It works all over, just not on the initial “On Scene Load”.

I even tried to emulate a click() of a button to play the sound, but no dice.

Every time I get this error output in the console: “Unhandled Promise Rejection: NotAllowedError (DOM Exception 35): The request is not allowed by the user agent or the platform in the current context, possibly because the user denied permission.” Which leads me to think that playing a sound upon initial load simply isn’t allowed without user input.

The weird thing is that by using Hypes “Play Sound…” inside “On Load Scene” it actually works. I’d love to know why this is the case, and if I can somehow target this sound although I can’t sign an ID to it. This way I would be able to pause it, and my problem would be solved.

PS. All this is a non-problem in Chrome, Firefox, and Edge/Explorer


#4

Maybe it’s because the latest Safari automatically is blocking sounds, unless you permit the website to play the sound? Take a look at ‘preferences/websites’


#5

Thx Djon, you are exactly right! Guess I can work around it now, by telling the client to turn on autoplay in the browser

I still wonder, though, what Hypes integrated “Play Sound…” action does to circumvent the restriction. Oh well, my problem is sort of solved now :slight_smile:


(Mark Hunte) #6

Very good point