Table of Contents

Class AudioStreamPlayer2D

Namespace
Godot
Assembly
GodotSharp.dll

Plays audio that is attenuated with distance to the listener.

By default, audio is heard from the screen center. This can be changed by adding an AudioListener2D node to the scene and enabling it by calling MakeCurrent() on it.

See also AudioStreamPlayer to play a sound non-positionally.

Note: Hiding an AudioStreamPlayer2D node does not disable its audio output. To temporarily disable an AudioStreamPlayer2D's audio output, set VolumeDb to a very low value like -100 (which isn't audible to human hearing).

public class AudioStreamPlayer2D : Node2D, IDisposable
Inheritance
AudioStreamPlayer2D
Implements
Inherited Members

Constructors

AudioStreamPlayer2D()

public AudioStreamPlayer2D()

Properties

AreaMask

Determines which Area2D layers affect the sound for reverb and audio bus effects. Areas can be used to redirect AudioStreams so that they play in a certain audio bus. An example of how you might use this is making a "water" area so that sounds played in the water are redirected through an audio bus to make them sound like they are being played underwater.

public uint AreaMask { get; set; }

Property Value

uint

Attenuation

The volume is attenuated over distance with this as an exponent.

public float Attenuation { get; set; }

Property Value

float

Autoplay

If true, audio plays when added to scene tree.

public bool Autoplay { get; set; }

Property Value

bool

Bus

Bus on which this audio is playing.

Note: When setting this property, keep in mind that no validation is performed to see if the given name matches an existing bus. This is because audio bus layouts might be loaded after this property is set. If this given name can't be resolved at runtime, it will fall back to "Master".

public StringName Bus { get; set; }

Property Value

StringName

MaxDistance

Maximum distance from which audio is still hearable.

public float MaxDistance { get; set; }

Property Value

float

MaxPolyphony

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

public int MaxPolyphony { get; set; }

Property Value

int

PanningStrength

Scales the panning strength for this node by multiplying the base ProjectSettings.audio/general/2d_panning_strength with this factor. Higher values will pan audio from left to right more dramatically than lower values.

public float PanningStrength { get; set; }

Property Value

float

PitchScale

The pitch and the tempo of the audio, as a multiplier of the audio sample's sample rate.

public float PitchScale { get; set; }

Property Value

float

Playing

If true, audio is playing or is queued to be played (see Play(float)).

public bool Playing { get; set; }

Property Value

bool

Stream

The AudioStream object to be played.

public AudioStream Stream { get; set; }

Property Value

AudioStream

StreamPaused

If true, the playback is paused. You can resume it by setting StreamPaused to false.

public bool StreamPaused { get; set; }

Property Value

bool

VolumeDb

Base volume before attenuation.

public float VolumeDb { get; set; }

Property Value

float

Methods

GetPlaybackPosition()

Returns the position in the AudioStream.

public float GetPlaybackPosition()

Returns

float

GetStreamPlayback()

Returns the AudioStreamPlayback object associated with this AudioStreamPlayer2D.

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 whether the AudioStreamPlayer can return the AudioStreamPlayback object or not.

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)

Queues the audio to play on the next physics frame, from the given position fromPosition, in seconds.

public void Play(float fromPosition = 0)

Parameters

fromPosition float

Seek(float)

Sets the position from which audio will be played, in seconds.

public void Seek(float toPosition)

Parameters

toPosition float

Stop()

Stops the audio.

public void Stop()

Events

Finished

Emitted when the audio stops playing.

public event Action Finished

Event Type

Action