0 votes
by (120 points)

Morning, everyone. New Twine user here. I fell into the catagory of using Harlowe 2.1.0. I enjoy it immensely, it's my first forray into coding since I was a youngster.

This morning I got an audio file to play through the Edit story javascript function through the desktop editor. Though, I'm unable to get it to play through the browser. I've sent the publication to a friend and have also tried it on my phone to no avail.

Here is the code: 

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

audio.src = 'https://www.dropbox.com/s/rvqkdfki2u4zrap/Game-Track-1%20%281%29.mp3?dl=1';

audio.loop = true;

audio.play();

I'm looking to atleast get the music to play at startup. Eventually I'd like to switch it as the game progresses.
Does anyone have a clue as to what's going on?

 

NOTE: Sound from the browser is allowed, I've checked it several times. I'm using Chrome and Twine 2.

1 Answer

0 votes
by (41.9k points)
Some browsers, mainly Chrome, do not allow audio to autoplay on startup, and they require some user interaction before they'll let audio play.  Have the user click to start the game (or something like that), start the audio at that point instead, and then it should work.

Twine doesn't have that same feature, which is why it works in Twine but not in Chrome.

Hope that helps!  :-)
...