AudioStreamPlayer
Inherits: Node < Object
Description
A node for audio playback. The AudioStreamPlayer node plays an audio stream non-positionally. It is ideal for user interfaces, menus, or background music.
Properties
The AudioStream resource to be played.
Volume of sound, in decibels.
The audio’s pitch and tempo, as a multiplier of the stream’s sample rate.
If true, this node is playing sounds.
If true, this node calls play when entering the tree.
bus
StringName
default:"Master"
The target bus name. All sounds from this node will be playing on this bus.
Methods
play
void play(from_position: float = 0.0)
Plays a sound from the beginning, or the given position in seconds.
Position in seconds to start playback from (default: 0.0)
stop
Stops all sounds from this node.
seek
void seek(to_position: float)
Restarts all sounds to be played from the given position, in seconds.
get_playback_position
float get_playback_position()
Returns the position in the AudioStream of the latest sound, in seconds.
Signals
finished()
Emitted when a sound finishes playing without interruptions.
Example Usage
var player = AudioStreamPlayer.new()
add_child(player)
# Load and play a sound
player.stream = load("res://sounds/music.ogg")
player.volume_db = -10.0
player.play()
# Connect to finished signal
player.finished.connect(func(): print("Sound finished"))
# Stop the sound
player.stop()
var player = new AudioStreamPlayer();
AddChild(player);
// Load and play a sound
player.Stream = GD.Load<AudioStream>("res://sounds/music.ogg");
player.VolumeDb = -10.0f;
player.Play();
// Connect to finished signal
player.Finished += () => GD.Print("Sound finished");