Skip to content

AudioStreamPlayback

Inherits: RefCounted < Object

Inherited by: AudioStreamPlaybackInteractive, AudioStreamPlaybackPlaylist, AudioStreamPlaybackPolyphonic, AudioStreamPlaybackResampled, AudioStreamPlaybackSynchronized

Meta class for playing back audio.

Can play, loop, pause a scroll through audio. See AudioStream and AudioStreamOggVorbis for usage.

Returns Method
int _get_loop_count() virtual const
Variant _get_parameter(name: StringName) virtual const
float _get_playback_position() virtual required const
bool _is_playing() virtual required const
int _mix(buffer: AudioFrame*, rate_scale: float, frames: int) virtual required
void _seek(position: float) virtual
void _set_parameter(name: StringName, value: Variant) virtual
void _start(from_pos: float) virtual required
void _stop() virtual required
void _tag_used_streams() virtual
int get_loop_count() const
float get_playback_position() const
AudioSamplePlayback get_sample_playback() const
bool is_playing() const
PackedVector2Array mix_audio(rate_scale: float, frames: int)
void seek(time: float = 0.0)
void set_sample_playback(playback_sample: AudioSamplePlayback)
void start(from_pos: float = 0.0)
void stop()

_get_loop_count

int _get_loop_count() virtual const

Overridable method. Should return how many times this audio stream has looped. Most built-in playbacks always return 0.

_get_parameter

Variant _get_parameter(name: StringName) virtual const

Return the current value of a playback parameter by name (see AudioStream._get_parameter_list()).

_get_playback_position

float _get_playback_position() virtual required const

Overridable method. Should return the current progress along the audio stream, in seconds.

_is_playing

bool _is_playing() virtual required const

Overridable method. Should return true if this playback is active and playing its audio stream.

_mix

int _mix(buffer: AudioFrame*, rate_scale: float, frames: int) virtual required

Override this method to customize how the audio stream is mixed. This method is called even if the playback is not active.

Note: It is not useful to override this method in C#. Only NativeExtension can take advantage of it.

_seek

void _seek(position: float) virtual

Override this method to customize what happens when seeking this audio stream at the given position, such as by calling AudioStreamPlayer.seek().

_set_parameter

void _set_parameter(name: StringName, value: Variant) virtual

Set the current value of a playback parameter by name (see AudioStream._get_parameter_list()).

_start

void _start(from_pos: float) virtual required

Override this method to customize what happens when the playback starts at the given position, such as by calling AudioStreamPlayer.play().

_stop

void _stop() virtual required

Override this method to customize what happens when the playback is stopped, such as by calling AudioStreamPlayer.stop().

_tag_used_streams

void _tag_used_streams() virtual

Overridable method. Called whenever the audio stream is mixed if the playback is active and AudioSystem.set_enable_tagging_used_audio_streams() has been set to true. Editor plugins may use this method to “tag” the current position along the audio stream and display it in a preview.

get_loop_count

int get_loop_count() const

Returns the number of times the stream has looped.

get_playback_position

float get_playback_position() const

Returns the current position in the stream, in seconds.

get_sample_playback

AudioSamplePlayback get_sample_playback() const

Returns the AudioSamplePlayback associated with this AudioStreamPlayback for playing back the audio sample of this stream.

is_playing

bool is_playing() const

Returns true if the stream is playing.

mix_audio

PackedVector2Array mix_audio(rate_scale: float, frames: int)

Mixes up to frames of audio from the stream from the current position, at a rate of rate_scale, advancing the stream.

Returns a PackedVector2Array where each element holds the left and right channel volume levels of each frame.

Note: Can return fewer frames than requested, make sure to use the size of the return value.

seek

void seek(time: float = 0.0)

Seeks the stream at the given time, in seconds.

set_sample_playback

void set_sample_playback(playback_sample: AudioSamplePlayback)

Associates AudioSamplePlayback to this AudioStreamPlayback for playing back the audio sample of this stream.

start

void start(from_pos: float = 0.0)

Starts the stream from the given from_pos, in seconds.

stop

void stop()

Stops the stream.