Twine version: 2.3.7
Story format: Harlowe 3.1.0
I’m trying to make an audio clip play in my starting passage, and finding that the audio doesn’t play when I start my story, but if I navigate to another passage, then navigate back to the starting passage, the audio plays fine. This is true in Chrome/Edge/Firefox, it’s true in Harlow and SugarCube, and it’s true whether I use <audio> or a <script> with createElement(‘audio’). The audio is specific to the first passage, I’m not trying to make audio that plays throughout the story (yet).
Is there anything unique about the first time the starting passage is rendered that would prevent audio from playing?
This is due to a “security feature” added to most browsers late last year. It’s intended to keep unexpected and unwanted audio from blasting a user when they first go to a web page, such as some annoying advertisements and spam do.
Basically, you just need to make sure that the user interacts with the page first, and then audio will be allowed to play after that. Typically this is done with a splash page with the game’s and/or author’s logo displayed, and the user needs to click to move past that, which then starts the audio.
Note: It’s strongly recommended that you have a mute button and/or a volume slider immediately available, in case they don’t want the audio to play or to play too loudly.
Hope that helps!
My audio library HAL features a
playWhenPossible() method/command intended to help get around autoplay restrictions. It includes the audio controls mentioned by HiEv as well so you don’t need to build them yourself.
Is there anything better than satisfying answers? That was a very satisfying answer. I added a splash screen, good enough for my situation. Thanks!