How to queue multiple AudioStreams?

Godot Version

4.2.2

Question

Unlike something like the AnimationPlayer, I can’t queue multiple AudioStreams on a AudioStreamPlayer so they play perfectly one after the other. My music composer is looking a way to play a piece of music that serves as an entry into the second piece of music which is a loop. How do I go about realizing this?

You can wait for Godot 4.3 to be released which add interactive music support Add interactive music support by reduz · Pull Request #64488 · godotengine/godot · GitHub you can play with it in the latest dev release as of today Dev snapshot: Godot 4.3 dev 6

For now your only option is to manually play the new audio when the last one finishes. You could use the AudioStreamPlayer.finished signal to play the next one.

1 Like

Ah dang, that looks great indeed! I’m not able to go into any dev or alpha versions because I’m making a game that’s set to release this year, but I’ll make the switch when able.

My music composer actually found another solution just now!! In the import settings of the AudioStream (the audio clip) you can enter a ‘loop begin’ and when you set loop to true, it’ll still play the clip from the very start – and start looping once it’s inside the loop area. Thumbs up!!

I don’t know if this is the correct post to ask but since search engine led me here maybe it might be:

How can you switch audio clips with the new interactive component?

Documentation does not mention any method for it:

There is this though, but I don’t understand how it would work in the code?

And why can’t the method be in the interactive component?

The AudioStreamInteractive is the Resource that contains the audio streams and transitions. The AudioStreamPlaybackInteractive is the object that let you control which audio clip to play at runtime.

For example:

extends Node


@onready var audio_stream_player: AudioStreamPlayer = $AudioStreamPlayer2
@onready var h_box_container: HBoxContainer = $HBoxContainer


func _ready() -> void:
	audio_stream_player.play()

	var audio_stream = audio_stream_player.stream as AudioStreamInteractive
	var playback = audio_stream_player.get_stream_playback() as AudioStreamPlaybackInteractive

	for i in audio_stream.clip_count:
		var clip_name = audio_stream.get_clip_name(i)
		var button = Button.new()
		button.text = clip_name
		h_box_container.add_child(button)
		button.pressed.connect(func(): playback.switch_to_clip_by_name(clip_name))

Result:

Thanks for the reply! I would have not quessed that the playback is needed to use like that. I tried to get the parameter with _get_parameter():

But seems like it has not been added yet to the 4.3, old methods do work so I tought I get to the switch parameter like that.