Background Music / Soundtrack Autoplay

Greetings friends,
Does anyone have success implementing a background soundtrack into a room or locked to an object. Something similar to the way the water-fountain or room-noise implementation.

2 Likes

I think you’re the one I spoke with earlier, but yes! Here’s Jeffrey Chen’s awesome tool to do that:

https://gt-item-shop.web.app/

(And if anyone else reading this finds this useful, please consider throwing a little thanks his way: https://www.buymeacoffee.com/JeffreyChen )

There are also some console commands that can be used to modify the sound objects, if you are hesitant to use an API key in a 3rd party site. I’ll dig around and try and pull something concise together.

1 Like

Thank you GV, that’s great! @Bill_Uncork-It - that would be useful too. Would love to see what you have.

Please read this entire post to use this code, I don’t want to ruin anyone’s space.

This will need to be pasted into the console (F12 in chrome) in the actual space (the part you walk around in), not Mapmaker.

So its not as concise as I would like it, but I wanted it to be readable for those who are new:

var room = "{ROOM NAME}"
var soundURL = "{HTTPS URL TO SOUND FILE}"
var obj = game.filterObjectsInMap(room, (e) => e.sound?.volume)[0]
obj.sound.src = soundURL
obj.sound.volume = {DESIRED VOLUME 0 - 1}
obj.sound.maxDistance = {DESIRED RANGE 1+}
game.setObject(room, obj.id, obj)

This can be copied into a text editor, and the {BRACKET} text replaced with your desired room, url, etc. The code does assume that you only have 1 sound emitter in the space. If you do not, add one from the Gather object picker, and this will modify it.

{ROOM NAME} needs to be the name you see in mapmaker on the right hand tab. Needs to be in quotes.
{HTTPS URL TO SOUND FILE} needs to be a direct HTTPS request to the sound file.
{DESIRED VOLUME 0 - 1} is a number between 0-1, I think. You can remove lines 1,2,4,&6 if you just want to alter the volume.
{DESIRED RANGE 1+} is the range from the emitter in Gather tiles. You can omit lines 1,2,4,&5 if you just want to alter the range.

Hopefully that helps!

3 Likes

This is wonderful, thank you for sharing.

Hi there! I’ve been trying to figure this out all day, but I keep getting this error…would you be to help me? I’m not sure where I’m going wrong.

Few things:
Make sure your room name is correct. “courtyard}” seems wrong, unless you added the bracket on purpose.

For the volume and distance, just use the number without brackets, so obj.sound.volume = {0} becomes obj.sound.volume = 0

And finally, the game.setObject function requires map Id, object id, and the object. It looks like you are trying to pass the object id as the first parameter, and not as a string. I think that is likely where the error is.

Regarding Jeffrey’s Tool, it seems the file must be a MP3 extension. How do i put in a URL link with a MP3 extension for the tool to work. It seems to bounce out and give me bad request.

Is the URL actually to an MP3 file, or are you adding the .mp3 in order to try and make it work? Also, you do have the correct permissions in the space? I think you might need both Builder and Admin, depending on what it is changing.

i am trying to add background sound to the space. i have builder only. Jeffrey’s tool could not work for files coming from dropbox or google drive. so i was wondering if i did it wrongly as his tool showed bad request.

I did somehow was able to somehow used the tool, but it turned out that there was no sound when i used the default sound link.

So i was wondering if the tool only accepts sound URL with ending “.mp3” on the link.

Makes sense. If I remember correctly, the issue is likely the Google Drive link, not the tool. Google Drive links have to be transformed to allow direct access to the file, instead of the wrapper Google normally provides.

There was a Stack Overflow post from a few years ago that helped me, Ill see if I can find it.

I found my notes from when I did this with google drive months ago, hope they still work. For the mp3 file in google drive, you should edit the share settings so that anyone can access, then get the share link. It will look like:
https://drive.google.com/file/d/BUNCHOFCHARACTERS/view?usp=sharing
Edit that link so that it looks like:
https://docs.google.com/uc?export=open&id=BUNCHOFCHARACTERS
And that link should work

2 Likes

thanks will try it later

Background sound based on

is not working on Firefox. :worried: