Inheritance #
- AudioServer
- CameraServer
- ClassDB
- DisplayServer
- EditorFileSystemDirectory
- EditorInterface
- EditorPaths
- EditorSelection
- EditorUndoRedoManager
- EditorVCSInterface
- Engine
- EngineDebugger
- FramebufferCacheRD
- GDExtensionManager
- Geometry2D
- Geometry3D
- IP
- Input
- InputMap
- JNISingleton
- JSONRPC
- JavaClassWrapper
- JavaScriptBridge
- MainLoop (1)
- Marshalls
- MovieWriter
- NativeMenu
- NavigationMeshGenerator
- NavigationServer2D
- NavigationServer3D
- Node (21)
- OS
- OpenXRExtensionWrapperExtension
- OpenXRInteractionProfileMetadata
- Performance
- PhysicsDirectBodyState2D (1)
- PhysicsDirectBodyState3D (1)
- PhysicsDirectSpaceState2D (1)
- PhysicsDirectSpaceState3D (1)
- PhysicsServer2D (1)
- PhysicsServer2DManager
- PhysicsServer3D (1)
- PhysicsServer3DManager
- PhysicsServer3DRendering
ServerHandler
- ProjectSettings
- RefCounted (121)
- RenderData (2)
- RenderSceneData (2)
- RenderingDevice
- RenderingServer
- ResourceLoader
- ResourceSaver
- ResourceUID
- ScriptLanguage (1)
- ShaderIncludeDB
- TextServerManager
- ThemeDB
- TileData
- Time
- TranslationServer
- TreeItem
- UndoRedo
- UniformSetCacheRD
- WorkerThreadPool
- XRServer
- XRVRS
- AnimationMixer (2)
- AudioStreamPlayer
- CanvasItem (2)
- CanvasLayer (1)
- EditorFileSystem
- EditorPlugin (1)
- EditorResourcePreview
- HTTPRequest
- InstancePlaceholder
- MissingNode
- MultiplayerSpawner
- MultiplayerSynchronizer
- NavigationAgent2D
- NavigationAgent3D
- Node3D (31)
- ResourcePreloader
- ShaderGlobalsOverride
- StatusIndicator
- Timer
- Viewport (2)
- WorldEnvironment
Table of contents
-
var autoplay: bool = false -
var bus: StringName = &"Master" -
var max_polyphony: int = 1 -
var mix_target = MIX_TARGET_STEREO -
var pitch_scale: float = 1.0 -
var playback_type = PLAYBACK_TYPE_DEFAULT -
var playing: bool = false -
var stream: AudioStream -
var stream_paused: bool = false -
var volume_db: float = 0.0 -
var volume_linear: float -
func get_playback_position() -> float -
func get_stream_playback() -> AudioStreamPlayback -
func has_stream_playback() -> bool -
func play(from_position: float = 0.0) -> void -
func seek(to_position: float) -> void -
func stop() -> void -
const MIX_TARGET_STEREO = 0 enum MixTarget -
const MIX_TARGET_SURROUND = 1 enum MixTarget -
const MIX_TARGET_CENTER = 2 enum MixTarget -
enum MixTarget -
signal finished()
AudioStreamPlayer #
is_instantiable, Node, core, not_builtin_classes
A node for audio playback.
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.
Members #
var autoplay: bool = false#
If true, this node calls play when entering the tree.
var bus: StringName = &"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.
var max_polyphony: int = 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.
var mix_target = MIX_TARGET_STEREO#
The mix target channels, as one of the MixTarget constants. Has no effect when two speakers or less are detected (see AudioServer.SpeakerMode).
var pitch_scale: float = 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.
var playback_type = PLAYBACK_TYPE_DEFAULT#
The playback type of the stream player. If set other than to the default value, it will force that playback type.
var playing: bool = false#
If true, this node is playing sounds. Setting this property has the same effect as play and stop.
var stream: AudioStream#
The AudioStream resource to be played. Setting this property stops all currently playing sounds. If left empty, the AudioStreamPlayer does not work.
var stream_paused: bool = 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).
var volume_db: float = 0.0#
Volume of sound, in decibels. This is an offset of the stream's volume.
Note: To convert between decibel and linear energy (like most volume sliders do), use volume_linear, or @GlobalScope.db_to_linear and @GlobalScope.linear_to_db.
var volume_linear: float#
Volume of sound, as a linear value.
Note: This member modifies volume_db for convenience. The returned value is equivalent to the result of @GlobalScope.db_to_linear on volume_db. Setting this member is equivalent to setting volume_db to the result of @GlobalScope.linear_to_db on a value.
Methods #
func get_playback_position() -> float#
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.
func get_stream_playback() -> AudioStreamPlayback#
Returns the latest AudioStreamPlayback of this node, usually the most recently created by play. If no sounds are playing, this method fails and returns an empty playback.
func has_stream_playback() -> bool#
Returns true if any sound is active, even if stream_paused is set to true. See also playing and get_stream_playback.
func play(from_position: float = 0.0) -> void#
Plays a sound from the beginning, or the given from_position in seconds.
func seek(to_position: float) -> void#
Restarts all sounds to be played from the given to_position, in seconds. Does nothing if no sounds are playing.
func stop() -> void#
Stops all sounds from this node.
Annotations #
Constants #
const MIX_TARGET_STEREO = 0 enum MixTarget#
The audio will be played only on the first channel. This is the default.
const MIX_TARGET_SURROUND = 1 enum MixTarget#
The audio will be played on all surround channels.
const MIX_TARGET_CENTER = 2 enum MixTarget#
The audio will be played on the second channel, which is usually the center.
Constructors #
Enums #
MixTarget#
enum MixTarget {
MIX_TARGET_STEREO = 0,
MIX_TARGET_SURROUND = 1,
MIX_TARGET_CENTER = 2,
} Operators #
Signals #
signal 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.