0 votes
by (130 points)

I'm working on my second Twine project, my first with Sugarcube. I wanted to play some music, and it works on the computer where I'm working and where the file is storaged, but not on other devices.

I've been a couple of hours searching the Q&A without much succes.

I'm using SugarCube 2.28.2, and this is the code in StoryInit:

<<cacheaudio "myth" "https://www.dropbox.com/s/aaf7yi7nd5rnh0n/Night%20Cave.mp3?dl=1">>
<<audio "myth" play>>

As I said, it works when I test it, and on the computer when I export it and play it, but not on other computers/tablets, etc.

FYI, I've tried changing the dropbox extension to raw=1 without any result. This is driving me crazy!

1 Answer

+1 vote
by (38.5k points)

Well, there are a couple of issues.

1) You should be using the "raw" version, so put this in your "StoryInit" passage:

<<cacheaudio "myth" "https://www.dropbox.com/s/aaf7yi7nd5rnh0n/Night%20Cave.mp3?raw=1">>>

Having it in "StoryInit" allows it to start caching the audio right away.

2) Some browsers, such as Chrome and Opera, require that you interact with the page before audio can play, for security reasons (basically so ads can't blast you with audio).  The simplest way is to have the audio start on the second passage you display, since the user will have to interact with the page to bring that up.  As a test to see if this is the case, we can use a button in your first passage:

<<button "Play">><<audio "myth" play>><</button>>

If that works, then you know it was the browser's security requiring you to interact with the page first.

3) You have to give it time to cache the audio before it will be able to play it.  How long that takes depends on how good your connection is and how fast the Dropbox servers are.  Generally, this means that if you're caching a whole bunch of different audio tracks that it may take a bit longer as well.  So, be a bit patient and don't expect it to always be able to play immediately.

If you're interested, I have some other sample code showing how to work with audio in Twine/SugarCube.  That includes a widget which caches audio as-needed.

Hope that helps!  :-)

by (130 points)
Thanks a lot!

It works with the button, and also with a link.

Not with automated timing, though. I guess, as you said, it needs interaction from the player. I checked your examples, but right now they are a little out of my league.

Thanks again!
Welcome to Twine Q&A, where you can ask questions and receive answers from other members of the community.

You can also find hints and information on Twine on the official wiki and the old forums archive.

See a spam question? Flag it instead of downvoting. A question flagged enough times will automatically be hidden while moderators review it.