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!

2 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.