AudioStreamPlayer
Plays sound without world-position attenuation.
AudioStreamPlayer suits music and interface sounds. Assign a Stream, choose a Bus and call Play() after entering the tree. Several players can share a resource with independent playback positions and pauses.
In Stream mode, a new Play creates a voice; MaxPolyphony limits voices by replacing the oldest. Pausing makes IsPlaying() false while retaining HasStreamPlayback(). Finished does not guarantee all voices have ended. Use a 2D/3D player for positional sources.
Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.
Constructors1
AudioStreamPlayerConstructor
public AudioStreamPlayer();Properties11
AutoplayProperty
public bool Autoplay { get; set; }If true, this node calls AudioStreamPlayer.Play when entering the tree.
BusProperty
public StringName Bus { get; set; }Name of the receiving bus. If it is absent from the layout, audio falls back to Master. Check GetBusIndex(name) during project setup so the fallback does not hide a typo.
MaxPolyphonyProperty
public int MaxPolyphony { get; set; }Maximum simultaneous voices in this player. A new Play exceeding the limit replaces the oldest voice. Use a positive value; choose 1 for a single controlled music stream.
MixTargetProperty
public AudioStreamPlayer.MixTargetEnum MixTarget { get; set; }The mix target channels. Has no effect when two speakers or less are detected (see AudioServer.SpeakerMode).
PitchScaleProperty
public float PitchScale { get; set; }A positive speed and pitch multiplier. A value of 2 raises pitch and speeds up an ordinary stream; this is not independent time stretching. Zero is not a pause: use StreamPaused.
PlaybackTypeProperty
public AudioServer.PlaybackType PlaybackType { get; set; }The playback type of the stream player. If set other than to the default value, it will force that playback type.
PlayingProperty
public bool Playing { get; set; }If true, this node is playing sounds. Setting this property has the same effect as AudioStreamPlayer.Play and AudioStreamPlayer.Stop.
StreamProperty
public AudioStream Stream { get; set; }The AudioStream resource to be played. Setting this property stops all currently playing sounds. If left empty, the AudioStreamPlayer does not work.
StreamPausedProperty
public bool StreamPaused { get; set; }Pauses or resumes existing voices. A pending pause is not retained when no voices exist. In Stream mode, pausing makes IsPlaying() false while HasStreamPlayback() remains true.
VolumeDbProperty
public float VolumeDb { get; set; }Volume of sound, in decibels. This is an offset of the AudioStreamPlayer.Stream's volume.
Note: To convert between decibel and linear energy (like most volume sliders do), use AudioStreamPlayer.VolumeLinear, or @GlobalScope.db_to_linear and @GlobalScope.linear_to_db.
VolumeLinearProperty
public float VolumeLinear { get; set; }Volume of sound, as a linear value.
Note: This member modifies AudioStreamPlayer.VolumeDb for convenience. The returned value is equivalent to the result of @GlobalScope.db_to_linear on AudioStreamPlayer.VolumeDb. Setting this member is equivalent to setting AudioStreamPlayer.VolumeDb to the result of @GlobalScope.linear_to_db on a value.
Methods28
GetBusStringName
public StringName GetBus();StringNameGetMaxPolyphonyint
public int GetMaxPolyphony();intGetMixTargetAudioStreamPlayer.MixTargetEnum
public AudioStreamPlayer.MixTargetEnum GetMixTarget();AudioStreamPlayer.MixTargetEnumGetPitchScalefloat
public float GetPitchScale();floatGetPlaybackPositionfloat
public float GetPlaybackPosition();Returns the most recently created voice's position in seconds, not the combined time of all voices. It can advance in steps between mixes. For a single stream at speed 1, time since the last mix can refine an estimate; handle pause, seeking and output latency separately.
floatGetPlaybackTypeAudioServer.PlaybackType
public AudioServer.PlaybackType GetPlaybackType();AudioServer.PlaybackTypeGetStreamAudioStream
public AudioStream GetStream();AudioStreamGetStreamPausedbool
public bool GetStreamPaused();boolGetStreamPlaybackAudioStreamPlayback
public AudioStreamPlayback GetStreamPlayback();Returns the most recently created playback object. Check HasStreamPlayback() first; without voices the method reports an error. A retained decoder reference does not prove its voice remains attached to the player/mixer.
AudioStreamPlaybackGetVolumeDbfloat
public float GetVolumeDb();floatGetVolumeLinearfloat
public float GetVolumeLinear();floatHasStreamPlaybackbool
public bool HasStreamPlayback();Checks whether the player retains playback objects, including paused ones. This does not prove audible output: mute, distance or pause can produce silence.
boolIsAutoplayEnabledbool
public bool IsAutoplayEnabled();boolIsPlayingbool
public bool IsPlaying();In Stream mode, returns true for an actively playing voice. Returns false while paused; use HasStreamPlayback() or StreamPaused to detect retained playback. Do not reject a resume command using this method.
boolPlayvoid
public void Play(float fromPosition = 0f);Creates playback of the assigned Stream at the requested position in seconds; requires the player inside the tree. Repeated calls add voices within MaxPolyphony rather than necessarily resuming an old one. Use StreamPaused = false to resume.
| Name | Type | Default |
|---|---|---|
fromPosition | float | 0f |
Seekvoid
public void Seek(float toPosition);Restarts the player at a position in seconds only while actively playing. Stops previous voices and starts a new one at the position. In Stream mode it does nothing while paused or stopped. To seek while retaining pause, save the flag, call Stop(), Play(position), then restore StreamPaused.
| Name | Type | Default |
|---|---|---|
toPosition | float | — |
SetAutoplayvoid
public void SetAutoplay(bool enable);| Name | Type | Default |
|---|---|---|
enable | bool | — |
SetBusvoid
public void SetBus(StringName bus);| Name | Type | Default |
|---|---|---|
bus | StringName | — |
SetMaxPolyphonyvoid
public void SetMaxPolyphony(int maxPolyphony);| Name | Type | Default |
|---|---|---|
maxPolyphony | int | — |
SetMixTargetvoid
public void SetMixTarget(AudioStreamPlayer.MixTargetEnum mixTarget);| Name | Type | Default |
|---|---|---|
mixTarget | AudioStreamPlayer.MixTargetEnum | — |
SetPitchScalevoid
public void SetPitchScale(float pitchScale);| Name | Type | Default |
|---|---|---|
pitchScale | float | — |
SetPlaybackTypevoid
public void SetPlaybackType(AudioServer.PlaybackType playbackType);| Name | Type | Default |
|---|---|---|
playbackType | AudioServer.PlaybackType | — |
SetPlayingvoid
public void SetPlaying(bool enable);| Name | Type | Default |
|---|---|---|
enable | bool | — |
SetStreamvoid
public void SetStream(AudioStream stream);| Name | Type | Default |
|---|---|---|
stream | AudioStream | — |
SetStreamPausedvoid
public void SetStreamPaused(bool pause);| Name | Type | Default |
|---|---|---|
pause | bool | — |
SetVolumeDbvoid
public void SetVolumeDb(float volumeDb);| Name | Type | Default |
|---|---|---|
volumeDb | float | — |
SetVolumeLinearvoid
public void SetVolumeLinear(float volumeLinear);| Name | Type | Default |
|---|---|---|
volumeLinear | float | — |
Stopvoid
public void Stop();Stops every voice in this player and clears its playback list. Does not emit Finished. Use Play() for a new start; this differs from resuming a pause.
Signals and events1
FinishedEvent
public event Action Finished;Emitted when an update removes one or more naturally ended voices. Other voices may still be playing. Stop() and voice-limit replacement are not natural completion; looping does not emit this signal each cycle.
AudioStreamPlayer.MixTargetEnum
| Value | Description |
|---|---|
Center = 2 | The audio will be played on the second channel, which is usually the center. |
Stereo = 0 | The audio will be played only on the first channel. This is the default. |
Surround = 1 | The audio will be played on all surround channels. |