A sibling API to play_sound: play_music

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
thesixthroc
Fast Inserter
Fast Inserter
Posts: 120
Joined: Wed Apr 29, 2020 9:53 pm
Contact:

A sibling API to play_sound: play_music

Post by thesixthroc »

Cerys would like custom music to start playing when the player begins launching the hydrogen nuke into orbit to complete the planet.

play_sound does not currently support overriding the music track and would need some extra functionality for this: the currently playing music track for players looking at the Cerys surface should gradually fade out and the override track fade in, perhaps with a customizable fade duration defaulting to ~10s.

The API should allow for playing 'sound' prototypes in addition to 'ambient-sound' such that a music track can appear only at this specific moment (or alternatively `hidden=true` music tracks that do not play normally could be supported).
Last edited by thesixthroc on Mon Oct 06, 2025 1:35 pm, edited 2 times in total.
mmmPI
Smart Inserter
Smart Inserter
Posts: 4767
Joined: Mon Jun 20, 2016 6:10 pm
Contact:

Re: A sibling API to play_sound: play_music

Post by mmmPI »

+1 for any kind of interaction possibilities with the music track currently playing even if just a fade out to play another sound at a particular moment

also +1 for the alternate proposition of hidden music to play at specific moment, like when someone dies or get run over by a train, currently you can play custom sounds but without control over the track currently playing it limits the options to avoid two tracks playing at the same time if the custom sound isn't "short".
Check out my latest mod ! It's noisy !
front
Burner Inserter
Burner Inserter
Posts: 18
Joined: Tue Dec 03, 2024 4:54 pm
Contact:

Re: A sibling API to play_sound: play_music

Post by front »

I'd support it. I have something in the backburner that needed this, and on my side for now I'll just add in an extra surface to have the music change. I think that solution is a little excessive, considering how much area I need that music for.
User avatar
snouz
Long Handed Inserter
Long Handed Inserter
Posts: 70
Joined: Sun Jan 03, 2021 6:01 pm
Contact:

Re: A sibling API to play_sound: play_music

Post by snouz »

+1
Planet Moshine, GUI Unifier + 17 mods, contributed graphically and otherwise to 70+ mods
Donion
Factorio Staff
Factorio Staff
Posts: 440
Joined: Sun Aug 22, 2021 9:18 am
Contact:

Re: A sibling API to play_sound: play_music

Post by Donion »

I'm open to this suggestion for 2.1 so let's figure out how it should look.

I'm imagining it would be done as an API to control the music player.

There would probably be the basics:
  • Play
  • Stop
  • Pause
  • Next
  • Previous
For more control there would be:
  • Select a track to play. It would use SoundPath but only ambient-sound would be accepted. There would be a new track_type, manual which would never be selected by the default music player track selection.
  • Transition control: fade-in/out
  • Some way to control how the music switches when switching surfaces?
Let's hear your ideas.
thesixthroc
Fast Inserter
Fast Inserter
Posts: 120
Joined: Wed Apr 29, 2020 9:53 pm
Contact:

Re: A sibling API to play_sound: play_music

Post by thesixthroc »

Nice.

I am not sure that a ‘stop’ feature is worthwhile. It seems to raise the possibility that another planet has stopped the music and it is still stopped when the player arrives at my planet — else, if it automatically resumes when changing surfaces, this still introduces footguns when returning to the original surface, such as the planet mod failing to interpret this switch correctly. If a mod is removed it may also miss its chance to resume a stopped music track for a planet.

A ‘resume’ feature has similar potential issues resulting from multiple overlapping content mods in Space Age — might you be resuming a different planet’s stopped track rather than your own?

Personally I would prefer that mods play keepy-uppy by regularly playing a silent track (while the player is looking at their surface) in order to temporarily prevent music for any given length of time.

On a different point, it is worth figuring out how to associate non-planet surfaces with music in order to support underground worlds, etc. Perhaps this could be implemented by writing to surfaces at runtime as borrowing the soundtrack of a given planet. This would open the possibility of a music overhaul mod assigning all surfaces to Nauvis-music in order to play all music manually without surface-switching interruptions. However custom soundtracks for underground worlds should ideally be supported.
Last edited by thesixthroc on Wed Oct 15, 2025 2:51 pm, edited 1 time in total.
FluidNatalie
Manual Inserter
Manual Inserter
Posts: 2
Joined: Tue Oct 14, 2025 7:52 pm
Contact:

Re: A sibling API to play_sound: play_music

Post by FluidNatalie »

I have a lot of ideas for the Music engine, but this is a start. I do think a global stop would still be good, I have been thinking of making a jukebox mod that adds a jukebox and music discs and this would be a perfect use case. Further more, just because the base game does not have dynamic music doesn't mean it should be absent from the API. I think one small change that could help would be having an optional "condition" that can be applied to tracks. It could include stuff like "if SPM ≥ 60, then the track can be played" or "if Evolution on surface ≤ then the track is disabled". I do not know if something like this would be possible given my middling knowledge of the engine but it is a small change that would fit the current system whilst allowing for "long-term" dynamic music.
User avatar
snouz
Long Handed Inserter
Long Handed Inserter
Posts: 70
Joined: Sun Jan 03, 2021 6:01 pm
Contact:

Re: A sibling API to play_sound: play_music

Post by snouz »

music_already_playing_mode = "interrupt" or "wait" or "play-on-top" or "interrupt-suddenly"
Planet Moshine, GUI Unifier + 17 mods, contributed graphically and otherwise to 70+ mods
mmmPI
Smart Inserter
Smart Inserter
Posts: 4767
Joined: Mon Jun 20, 2016 6:10 pm
Contact:

Re: A sibling API to play_sound: play_music

Post by mmmPI »

It's hard to find where to begin, i think the most general use case for such API would be for a mod to allow players to have control over the music that is played even in "vanilla" game. In some game you can go to the "music" menu and then you have a list of the song, so you can tick or untick them to include them or not in the playlist, and you have a little widget that allows you to "skip" a song, play previous, pause or stop, ( the 'basics') , and i think Factorio is a game whose pace of action allows this. ( manual track could be "unticked" by default, but accessible "manually" and maybe hero-track too after their first hearing ).

I can imagine how this could lead to some conflicts with the other use cases which would be modders trying to add their music theme to enhance the immersion of their planets or even something that isn't a surface , like between different mods ( silly idea : a vehicule radio mod that play some specfic music when you're in a train or in a car, and a funky or battle armor mod where you only hear funky or battle music when wearing the armor ) Those could in theory be made easier if there is some control offered over the music currently played but then I think there would need to be some logic to handle wether the vehicule "radio" or the "armor music" has priority, what is the players going to hear ? If the example are dumb maybe a more realistic situation would be with a mod that wants to add gloomy music when it's night time. Then when it's night time in a modded planet with its own track, there is a risk of conflict. I don't have established opinion on what would be an elegant way to handle this.

I think if the default for "play music" is to just be a one off thing that plays the track selected and resume to "normal" after it's done while interrupting any song that could have been playing and you can use it at runtime, it would be fine for me for the mods i could make. I would see it as overriding any surface related settings, and would call another "play music" timed for when the previous song finishes if the condition are still met.
Check out my latest mod ! It's noisy !
Donion
Factorio Staff
Factorio Staff
Posts: 440
Joined: Sun Aug 22, 2021 9:18 am
Contact:

Re: A sibling API to play_sound: play_music

Post by Donion »

Maybe let's take a step back and decide what the goal of this music API should be.

One route we could go with is to enable complete control of the music player for mods, this would allow to create jukebox/playlists kind of mods. This would most likely require the music player to have a 'manual' or 'scripted' playback mode. When set to that mode it would be completely up to the mod to control music.
This would obviously be a decent amount of effort. And I can already hear someone asking for multiple tracks (layers) playing at the same time and/or some other feature creep (which I'm not completely against, if there is a good usecase).

The other option is to just provide a way to 'override' the regular playback with a specific track as a one-time thing. This has the potential of introducing conflicts.

Personally I don't have a clear idea or preference yet, so I welcome your points of view.
front
Burner Inserter
Burner Inserter
Posts: 18
Joined: Tue Dec 03, 2024 4:54 pm
Contact:

Re: A sibling API to play_sound: play_music

Post by front »

My goal is to change the track (either to one track, or pick from a playlist) when the player enters a specific area on the map, then change it back when either leaving or completing a task. Effectively an enhancement to the game's dynamic music because I can know when to change it.
I'm fine with it resetting if the player leaves the surface or dies.

I can easily track when the player enters or leaves with a script already, originally I was thinking about trying to write an entire music engine with play_sound then settled on making those areas a separate surface entirely. That is what I may roll with when I get there.
FluidNatalie
Manual Inserter
Manual Inserter
Posts: 2
Joined: Tue Oct 14, 2025 7:52 pm
Contact:

Re: A sibling API to play_sound: play_music

Post by FluidNatalie »

I do think that, the current system with the playlist is way to basic for much depth. So something that I would want in is the ability to link conditions to whether a song is on the playlist or not (as I have stated above). Otherwise I would prefer that music if scripted can be completely controlled by the modders as this would let us remake our own version of the music system in a way that we want.
front
Burner Inserter
Burner Inserter
Posts: 18
Joined: Tue Dec 03, 2024 4:54 pm
Contact:

Re: A sibling API to play_sound: play_music

Post by front »

I think playing the track, or one track from a list then going back to the normal ambient is also a good option. Then you don't need to track how long is your track then turn back to the regular music.
mmmPI
Smart Inserter
Smart Inserter
Posts: 4767
Joined: Mon Jun 20, 2016 6:10 pm
Contact:

Re: A sibling API to play_sound: play_music

Post by mmmPI »

I'm still struggling to understand how a play_music can work in practice , compared to play_sound. I may be wrong, i think for the 2nd (play_sound), you need a location, a tile or a whole surface, and then all players hear both the regular music AND the sound played by play_sound if they are near that location or on that surface. So it would make sense for a capsule or a speaker to trigger such thing. But for a play_music, it's no so clear to me what should / could happen if it's triggered by circuit, like in a speaker, or a player uses a capsule, ( or wear an armor or enter a vehicule ), it would/should affect only the one player responsible. But it would also make sense that a mod wants to trigger a special music for all players when something important is occuring in the game. ( like Cerys in OP ) I don't know enough to be sure i understand the differences between the 2 propositions.

Having tried to use multiple layers at the same time, i'd say not having it sound terrible feels quite the achievement in itself x), there are some possibilities available already, but i haven't seen them used all that much, i wouldn't ask for more anytime soon, i have like a long list of things i'd like to try already, i see in this proposition a way to ease "working with the existing capabilities", being able to interrupt a track after 20 second, and restart it to see if the randomization works as expected with a proper not hacky way would be nice. I think that would also align with some players that would press the "previous" or "repeat" button for their favourite track if there was such function.

Maybe the larger use case would be modders that have popular mods that use the API to add a little something to their mod instead of those individual users for vanilla music after all, i have no idea.

I would welcome any improvement over the control given to mods on the music "currently" playing, so my opinion is favourable to both :) but my point of view is quite uninformed , too much to be more precise :)
Check out my latest mod ! It's noisy !
Post Reply

Return to “Modding interface requests”