Can't make audio play in browser

Please specify version and format if asking for help, or apply optional tags above:
Twine Version: 2.3.5
Story Format: SugarCube 2.30.0

I think I’ve found a post in every forum imaginable about this problem, but I still have no solution that works for me.
I can’t make audio play from my game in browser.
I know the code itself is correct: first I cache the sound file in the StoryInit passage - e.g. cacheaudio “mainsong” “Music/Glitterhater.MP3” - then when I need it to play, the code is audio mainsong play.
Whenever I make these changes, I publish to file. The relative pathways are correct, I’ve quadruple checked.
All my audio is MP3, so it’s not an issue with file type.
I know the audio should work, because when I play it from the .html file, the audio plays like a dream. But when I play it in the Twine application, or play it on itch . io, no audio. None.
I have made sure nothing is trying to play in the first passage, which I understand is occasionally a issue due to some bug with this version of Twine. I have tried playing the game on multiple browsers (Chrome, Firefox, Microsoft Edge). I have tried playing the game via itch.io on someone else’s device in multiple browsers.
No. Damn. Sound.
If anybody can help me, I’d be so grateful. I can provide more info upon request.
Thanks.
https://lipstix.itch.io/by-harald-lattimore

1 Like

The intro is very nice. I like the computer simulation.

1 Like

Looks like a case-sensitivity error: if I try “Music/Glitterhater.mp3” that works for me.

Also, yeah, I wouldn’t expect it to work from the Twine application because it will be running the html file from a temporary directory and not in the directory where your published html file (and your music files) are. I think there are workarounds for that but I’m blanking on where to find them at the moment, sorry.

1 Like

That’s fixed it!!
I’m so pleased thank you so much!!

Thanks, I enjoyed making that bit.

1 Like

You might want to take a look at my Twine/SugarCube sample code collection. The “Music” section not only shows how to add music so that it plays properly, both when launched from Twine and when played from the published HTML file, but also explains how to get around a browser security issue you might run into, how to add a volume slider, and other tips and tricks related to using audio.

Hope that helps! :smiley:

1 Like