Continuous Music

Hi! I was wondering how I can make a music file play continuously across rooms in the gamebook version of Quest?

There's an action tab in each room that allows me to select a music file and check a box that says "continue to play sound after player moves to another page". This makes it so the track plays on in the background as the player moves between pages, but the track does not loop and there is no option to make it loop.

Conversely, if I play a track using the script + text utility, it lets me pass an argument to loop the track, but it immediately stops playing in the next room. The only "workaround" is setting up the script in said other room, but that makes it so it resets and it sounds very clunky and unpleasant.

I want a track that loops to be played throughout some pages without interruption. Is that possible?


Hello,

Are you making this game in the Windows desktop version of Quest, or are you creating it using the online editor? (It will make a big difference in the code I should post to help.)


Also, is your audio file an MP3? If yes, you'll need to convert it to an OGG for my trick to work when your game is played in the desktop version of Quest.


Online or desktop:

NOTE: You'll need your file to be in the OGG format for this to work in the desktop version of Quest. It won't play an MP3 this way (from an HTML <audio> tag) due its built-in browser's capabilities.


Click on the game object, and go to the "Script" tab.


Click the </> button, and paste this into Code View:

firsttime {
  // User your file's name in place of "snd effect.ogg"
  filename = "snd effect.ogg"
  src = GetFileURL(filename)
  JS.eval ("$('" + Chr(60) + "audio src=\"" + src + "\" autoplay loop />').appendTo($('body'));")
}

Hello!

Windows desktop yes, I converted my music files to .ogg and that code works perfectly, thank you.


Cool.

If you plan to release the game publicly and the audio matters, I would advise testing things on every device on every browser you can. (HTML audio behaves inconsistently.)


UPDATE

I think I've made this work using the MP3 format and the built-in Quest play sound script.

https://textadventures.co.uk/games/view/lvpuzptewewpxgktagcnta/loop-it


I can't test on anything Apple.

If that plays the music and loops across pages continuously on a Mac, an iPhone, and an iPad, I'll post a link to the library I made for this.

If it isn't confirmed that it works on all devices, I probably won't share the code. (I'd hate to get anyone's hopes up, only for them to end up with reviews complaining about some devices not playing the audio in their game.)


NOTES

In the desktop player, the music should just play when the game begins.

There should also be a "save" button in the desktop player.

Online, there will be a prompt when play begins (in a new game or from a saved game), asking if the player is OK with audio.

  • This is to get the user to interact with the page, which will allow autoplay.
  • If they click no, the game will end.

When resuming play from a save, everything should work the same: The desktop player should simply start the music, and the web player should prompt you.


ALSO

There is a "bug" in the package the Quest web player uses to detect mobile devices. (It's not really a bug, it's just an old package.) When using Firefox on an Android phone, Quest will usually not redirect to the mobile player. This game has code to fix that, and it works on my device -- but I don't have a tablet to test it and I worry that it might make tablets switch to the mobile player.


ALSO ALSO

When I close Firefox in my Android phone with the game running and the music playing, the music does not stop playing when Firefox closes. I have to stop the music from the Notifications. (I didn't expect this behavior at all.)

UPDATE
It seems that the update I just posted fixes this.


This topic is now closed. Topics are closed after 14 days of inactivity.

Support

Forums