Skip to main content

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

stream
AudioStream
The AudioStream resource to be played.
volume_db
float
default:"0.0"
Volume of sound, in decibels.
pitch_scale
float
default:"1.0"
The audio’s pitch and tempo, as a multiplier of the stream’s sample rate.
playing
bool
default:"false"
If true, this node is playing sounds.
autoplay
bool
default:"false"
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.
from_position
float
Position in seconds to start playback from (default: 0.0)

stop

void 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()

Build docs developers (and LLMs) love