Class reference

AudioStreamPlayer

Inherits Node

A node for audio playback.

Description

The AudioStreamPlayer node plays an audio stream non-positionally. It is ideal for user interfaces, menus, or background music. To use this node, stream needs to be set to a valid AudioStream resource. Playing more than one sound at the same time is also supported, see max_polyphony. If you need to play audio at a specific position, use AudioStreamPlayer2D or AudioStreamPlayer3D instead.

Properties

bool autoplay = false

If true, this node calls play() when entering the tree.

StringName bus = &"Master"

The target bus name. All sounds from this node will be playing on this bus. Note: At runtime, if no bus with the given name exists, all sounds will fall back on "Master". See also AudioServer.get_bus_name().

int max_polyphony = 1

The maximum number of sounds this node can play at the same time. Calling play() after this value is reached will cut off the oldest sounds.

float pitch_scale = 1.0

The audio's pitch and tempo, as a multiplier of the stream's sample rate. A value of 2.0 doubles the audio's pitch, while a value of 0.5 halves the pitch.

int playback_type = 0

Experimental.

The playback type of the stream player. If set other than to the default value, it will force that playback type.

bool playing = false

If true, this node is playing sounds. Setting this property has the same effect as play() and stop().

bool stream_paused = false

If true, the sounds are paused. Setting stream_paused to false resumes all sounds. Note: This property is automatically changed when exiting or entering the tree, or this node is paused (see Node.process_mode).

Methods

float get_playback_position()

Returns the position in the AudioStream of the latest sound, in seconds. Returns 0.0 if no sounds are playing. Note: The position is not always accurate, as the AudioServer does not mix audio every processed frame. To get more accurate results, add AudioServer.get_time_since_last_mix() to the returned position. Note: This method always returns 0.0 if the stream is an AudioStreamInteractive, since it can have multiple clips playing at once.

void play(float from_position = 0.0)

Plays a sound from the beginning, or the given from_position in seconds.

void seek(float to_position)

Restarts all sounds to be played from the given to_position, in seconds. Does nothing if no sounds are playing.

void stop()

Stops all sounds from this node.

Signals

finished()

Emitted when a sound finishes playing without interruptions. This signal is not emitted when calling stop(), or when exiting the tree while sounds are playing.

Constants

MIX_TARGET_STEREO = 0

Enum: MixTarget

The audio will be played only on the first channel. This is the default.

MIX_TARGET_SURROUND = 1

Enum: MixTarget

The audio will be played on all surround channels.

MIX_TARGET_CENTER = 2

Enum: MixTarget

The audio will be played on the second channel, which is usually the center.

Tutorials

Source revision 5592dc3a7a61
Connection interrupted. Reload×

Rejoining the server...

Rejoin failed... trying again in seconds.

Failed to rejoin.
Please retry or reload the page.

The session has been paused by the server.

Failed to resume the session.
Please retry or reload the page.