Table of Contents

Class AudioStreamPlayer

Namespace
Godot
Assembly
GodotSharp.dll

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 MaxPolyphony.

If you need to play audio at a specific position, use AudioStreamPlayer2D or AudioStreamPlayer3D instead.

public class AudioStreamPlayer : Node, IDisposable
Inheritance
AudioStreamPlayer
Implements
Inherited Members

Constructors

AudioStreamPlayer()

public AudioStreamPlayer()

Properties

Autoplay

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

public bool Autoplay { get; set; }

Property Value

bool

Bus

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 GetBusName(int).

public StringName Bus { get; set; }

Property Value

StringName

MaxPolyphony

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

public int MaxPolyphony { get; set; }

Property Value

int

MixTarget

The mix target channels, as one of the AudioStreamPlayer.MixTargetEnum constants. Has no effect when two speakers or less are detected (see AudioServer.SpeakerMode).

public AudioStreamPlayer.MixTargetEnum MixTarget { get; set; }

Property Value

AudioStreamPlayer.MixTargetEnum

PitchScale

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.

public float PitchScale { get; set; }

Property Value

float

PlaybackType

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

public AudioServer.PlaybackType PlaybackType { get; set; }

Property Value

AudioServer.PlaybackType

Playing

If true, this node is playing sounds. Setting this property has the same effect as Play(float) and Stop().

public bool Playing { get; set; }

Property Value

bool

Stream

The AudioStream resource to be played. Setting this property stops all currently playing sounds. If left empty, the AudioStreamPlayer does not work.

public AudioStream Stream { get; set; }

Property Value

AudioStream

StreamPaused

If true, the sounds are paused. Setting StreamPaused to false resumes all sounds.

Note: This property is automatically changed when exiting or entering the tree, or this node is paused (see ProcessMode).

public bool StreamPaused { get; set; }

Property Value

bool

VolumeDb

Volume of sound, in decibel. This is an offset of the Stream's volume.

Note: To convert between decibel and linear energy (like most volume sliders do), use @GlobalScope.db_to_linear and @GlobalScope.linear_to_db.

public float VolumeDb { get; set; }

Property Value

float

Methods

GetPlaybackPosition()

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 GetTimeSinceLastMix() to the returned position.

public float GetPlaybackPosition()

Returns

float

GetStreamPlayback()

Returns the latest AudioStreamPlayback of this node, usually the most recently created by Play(float). If no sounds are playing, this method fails and returns an empty playback.

public AudioStreamPlayback GetStreamPlayback()

Returns

AudioStreamPlayback

HasGodotClassMethod(in godot_string_name)

Check if the type contains a method with the given name. This method is used by Godot to check if a method exists before invoking it. Do not call or override this method.

protected override bool HasGodotClassMethod(in godot_string_name method)

Parameters

method godot_string_name

Name of the method to check for.

Returns

bool

HasGodotClassSignal(in godot_string_name)

Check if the type contains a signal with the given name. This method is used by Godot to check if a signal exists before raising it. Do not call or override this method.

protected override bool HasGodotClassSignal(in godot_string_name signal)

Parameters

signal godot_string_name

Name of the signal to check for.

Returns

bool

HasStreamPlayback()

Returns true if any sound is active, even if StreamPaused is set to true. See also Playing and GetStreamPlayback().

public bool HasStreamPlayback()

Returns

bool

InvokeGodotClassMethod(in godot_string_name, NativeVariantPtrArgs, out godot_variant)

Invokes the method with the given name, using the given arguments. This method is used by Godot to invoke methods from the engine side. Do not call or override this method.

protected override bool InvokeGodotClassMethod(in godot_string_name method, NativeVariantPtrArgs args, out godot_variant ret)

Parameters

method godot_string_name

Name of the method to invoke.

args NativeVariantPtrArgs

Arguments to use with the invoked method.

ret godot_variant

Value returned by the invoked method.

Returns

bool

Play(float)

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

public void Play(float fromPosition = 0)

Parameters

fromPosition float

Seek(float)

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

public void Seek(float toPosition)

Parameters

toPosition float

Stop()

Stops all sounds from this node.

public void Stop()

Events

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.

public event Action Finished

Event Type

Action