0 votes
by (180 points)

I have used javascript to have a constant loop for background music and it successfully plays in the DESKTOP version of TWINE but when I try to open my .html file in chrome, the music doesn't play. 

The javascript I am using is: 

var audio= document.createElement('audio');
audio.src=
	'https://alexisgamearchive.yolasite.com/resources/Luma.mp3';
audio.loop = true;
audio.play();

Does anyone know how to make this work in chrome? 

Pls. 

2 Answers

0 votes
by (2.7k points)
Is it possible, that playing sound is disabled in the settings of the chrome browser?
by (159k points)
Does the same story HTML file work correctly within a different brand of web-browser?
by (180 points)
HELLO! YES!

IT DOES...

WHY?

WHY DOES IT DO THAT?

(Is there anyway you know what specific setting would effect this? I'm new to google chrome and twine and I just downloaded firefox to test that it indeed does work in an alternate web browser. Our professor is grading these games with the use of chrome and I want to make sure it's just my settings and not a lack of coding?)

Thank you :(
by (159k points)

The reason I asks was to determine if the sound in your story worked at all, or if the issue was only related to the Chrome web-browser.

As you could hear the sound from your story HTML file in another brand of web-browser then that generally means that the problem isn't in the HTML file itself. This probably means the problem has something to do with the Chrome web-browser itself.

Chrome has a setting which allows sound to be muted either for a particular web-page or for all web-pages.

Do you hear sound when you use Chrome to visit a different web-site (like YouTube or Spotify) on the internet? If so then the Chrome sound setting hasn't been turned of completely.

This article explains where to find Chrome's sound setting, in your case you need to make sure that the Allow sites to play sound (recommended) setting appears turned on.

0 votes
by (2.2k points)

Chrome sometimes prevent pages from playing audio until user interacts with page. Solution would be to create some kind of splash/intro screen and call audio.play() when user clicks "start" leading to first actual passage of your story.

by (180 points)
I'm not quite sure how to do that. Is there a specific code? Would I be putting that into my javascript? Sorry, I'm still learning!
by (2.2k points)

If you're using SugarCube, you can do it like this:
Create a passage called SplashScreen or something and make it starting passage. Put there following code:

<<link [[Play game|Start]]>><<audio "bgmusic" loop>><</link>>

Don't forget to change Start and bgmusic bits to your own values.

 

If you're using Harlowe, I can't provide implementation details, but my advice stands: call audio.play() only when user clicks something.

...