|
@@ -15,16 +15,18 @@ AudioStreamPlayer
|
|
|
|
|
|
**Inherits:** :ref:`Node<class_Node>` **<** :ref:`Object<class_Object>`
|
|
|
|
|
|
-Plays back audio non-positionally.
|
|
|
+A node for audio playback.
|
|
|
|
|
|
.. rst-class:: classref-introduction-group
|
|
|
|
|
|
Description
|
|
|
-----------
|
|
|
|
|
|
-Plays an audio stream non-positionally.
|
|
|
+The **AudioStreamPlayer** node plays an audio stream non-positionally. It is ideal for user interfaces, menus, or background music.
|
|
|
|
|
|
-To play audio positionally, use :ref:`AudioStreamPlayer2D<class_AudioStreamPlayer2D>` or :ref:`AudioStreamPlayer3D<class_AudioStreamPlayer3D>` instead of **AudioStreamPlayer**.
|
|
|
+To use this node, :ref:`stream<class_AudioStreamPlayer_property_stream>` needs to be set to a valid :ref:`AudioStream<class_AudioStream>` resource. Playing more than one sound at the time is also supported, see :ref:`max_polyphony<class_AudioStreamPlayer_property_max_polyphony>`.
|
|
|
+
|
|
|
+If you need to play audio at a specific position, use :ref:`AudioStreamPlayer2D<class_AudioStreamPlayer2D>` or :ref:`AudioStreamPlayer3D<class_AudioStreamPlayer3D>` instead.
|
|
|
|
|
|
.. rst-class:: classref-introduction-group
|
|
|
|
|
@@ -33,15 +35,15 @@ Tutorials
|
|
|
|
|
|
- :doc:`Audio streams <../tutorials/audio/audio_streams>`
|
|
|
|
|
|
-- `2D Dodge The Creeps Demo <https://godotengine.org/asset-library/asset/515>`__
|
|
|
+- `2D Dodge The Creeps Demo <https://godotengine.org/asset-library/asset/2712>`__
|
|
|
|
|
|
-- `Audio Device Changer Demo <https://godotengine.org/asset-library/asset/525>`__
|
|
|
+- `Audio Device Changer Demo <https://godotengine.org/asset-library/asset/2758>`__
|
|
|
|
|
|
-- `Audio Generator Demo <https://godotengine.org/asset-library/asset/526>`__
|
|
|
+- `Audio Generator Demo <https://godotengine.org/asset-library/asset/2759>`__
|
|
|
|
|
|
-- `Audio Mic Record Demo <https://godotengine.org/asset-library/asset/527>`__
|
|
|
+- `Audio Microphone Record Demo <https://godotengine.org/asset-library/asset/2760>`__
|
|
|
|
|
|
-- `Audio Spectrum Demo <https://godotengine.org/asset-library/asset/528>`__
|
|
|
+- `Audio Spectrum Visualizer Demo <https://godotengine.org/asset-library/asset/2762>`__
|
|
|
|
|
|
.. rst-class:: classref-reftable-group
|
|
|
|
|
@@ -108,7 +110,7 @@ Signals
|
|
|
|
|
|
**finished**\ (\ )
|
|
|
|
|
|
-Emitted when the audio stops playing.
|
|
|
+Emitted when a sound finishes playing without interruptions. This signal is *not* emitted when calling :ref:`stop<class_AudioStreamPlayer_method_stop>`, or when exiting the tree while sounds are playing.
|
|
|
|
|
|
.. rst-class:: classref-section-separator
|
|
|
|
|
@@ -131,7 +133,7 @@ enum **MixTarget**:
|
|
|
|
|
|
:ref:`MixTarget<enum_AudioStreamPlayer_MixTarget>` **MIX_TARGET_STEREO** = ``0``
|
|
|
|
|
|
-The audio will be played only on the first channel.
|
|
|
+The audio will be played only on the first channel. This is the default.
|
|
|
|
|
|
.. _class_AudioStreamPlayer_constant_MIX_TARGET_SURROUND:
|
|
|
|
|
@@ -169,7 +171,7 @@ Property Descriptions
|
|
|
- |void| **set_autoplay**\ (\ value\: :ref:`bool<class_bool>`\ )
|
|
|
- :ref:`bool<class_bool>` **is_autoplay_enabled**\ (\ )
|
|
|
|
|
|
-If ``true``, audio plays when added to scene tree.
|
|
|
+If ``true``, this node calls :ref:`play<class_AudioStreamPlayer_method_play>` when entering the tree.
|
|
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
|
@@ -186,9 +188,9 @@ If ``true``, audio plays when added to scene tree.
|
|
|
- |void| **set_bus**\ (\ value\: :ref:`StringName<class_StringName>`\ )
|
|
|
- :ref:`StringName<class_StringName>` **get_bus**\ (\ )
|
|
|
|
|
|
-Bus on which this audio is playing.
|
|
|
+The target bus name. All sounds from this node will be playing on this bus.
|
|
|
|
|
|
-\ **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"``.
|
|
|
+\ **Note:** At runtime, if no bus with the given name exists, all sounds will fall back on ``"Master"``. See also :ref:`AudioServer.get_bus_name<class_AudioServer_method_get_bus_name>`.
|
|
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
|
@@ -205,7 +207,7 @@ Bus on which this audio is playing.
|
|
|
- |void| **set_max_polyphony**\ (\ value\: :ref:`int<class_int>`\ )
|
|
|
- :ref:`int<class_int>` **get_max_polyphony**\ (\ )
|
|
|
|
|
|
-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.
|
|
|
+The maximum number of sounds this node can play at the same time. Calling :ref:`play<class_AudioStreamPlayer_method_play>` after this value is reached will cut off the oldest sounds.
|
|
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
|
@@ -222,7 +224,7 @@ The maximum number of sounds this node can play at the same time. Playing additi
|
|
|
- |void| **set_mix_target**\ (\ value\: :ref:`MixTarget<enum_AudioStreamPlayer_MixTarget>`\ )
|
|
|
- :ref:`MixTarget<enum_AudioStreamPlayer_MixTarget>` **get_mix_target**\ (\ )
|
|
|
|
|
|
-If the audio configuration has more than two speakers, this sets the target channels. See :ref:`MixTarget<enum_AudioStreamPlayer_MixTarget>` constants.
|
|
|
+The mix target channels, as one of the :ref:`MixTarget<enum_AudioStreamPlayer_MixTarget>` constants. Has no effect when two speakers or less are detected (see :ref:`SpeakerMode<enum_AudioServer_SpeakerMode>`).
|
|
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
|
@@ -239,7 +241,7 @@ If the audio configuration has more than two speakers, this sets the target chan
|
|
|
- |void| **set_pitch_scale**\ (\ value\: :ref:`float<class_float>`\ )
|
|
|
- :ref:`float<class_float>` **get_pitch_scale**\ (\ )
|
|
|
|
|
|
-The pitch and the tempo of the audio, as a multiplier of the audio sample's sample rate.
|
|
|
+The audio's pitch and tempo, as a multiplier of the :ref:`stream<class_AudioStreamPlayer_property_stream>`'s sample rate. A value of ``2.0`` doubles the audio's pitch, while a value of ``0.5`` halves the pitch.
|
|
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
|
@@ -255,7 +257,7 @@ The pitch and the tempo of the audio, as a multiplier of the audio sample's samp
|
|
|
|
|
|
- :ref:`bool<class_bool>` **is_playing**\ (\ )
|
|
|
|
|
|
-If ``true``, audio is playing.
|
|
|
+If ``true``, this node is playing sounds. Setting this property has the same effect as :ref:`play<class_AudioStreamPlayer_method_play>` and :ref:`stop<class_AudioStreamPlayer_method_stop>`.
|
|
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
|
@@ -272,7 +274,7 @@ If ``true``, audio is playing.
|
|
|
- |void| **set_stream**\ (\ value\: :ref:`AudioStream<class_AudioStream>`\ )
|
|
|
- :ref:`AudioStream<class_AudioStream>` **get_stream**\ (\ )
|
|
|
|
|
|
-The :ref:`AudioStream<class_AudioStream>` object to be played.
|
|
|
+The :ref:`AudioStream<class_AudioStream>` resource to be played. Setting this property stops all currently playing sounds. If left empty, the **AudioStreamPlayer** does not work.
|
|
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
|
@@ -289,7 +291,9 @@ The :ref:`AudioStream<class_AudioStream>` object to be played.
|
|
|
- |void| **set_stream_paused**\ (\ value\: :ref:`bool<class_bool>`\ )
|
|
|
- :ref:`bool<class_bool>` **get_stream_paused**\ (\ )
|
|
|
|
|
|
-If ``true``, the playback is paused. You can resume it by setting :ref:`stream_paused<class_AudioStreamPlayer_property_stream_paused>` to ``false``.
|
|
|
+If ``true``, the sounds are paused. Setting :ref:`stream_paused<class_AudioStreamPlayer_property_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 :ref:`Node.process_mode<class_Node_property_process_mode>`).
|
|
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
|
@@ -306,7 +310,9 @@ If ``true``, the playback is paused. You can resume it by setting :ref:`stream_p
|
|
|
- |void| **set_volume_db**\ (\ value\: :ref:`float<class_float>`\ )
|
|
|
- :ref:`float<class_float>` **get_volume_db**\ (\ )
|
|
|
|
|
|
-Volume of sound, in dB.
|
|
|
+Volume of sound, in decibel. This is an offset of the :ref:`stream<class_AudioStreamPlayer_property_stream>`'s volume.
|
|
|
+
|
|
|
+\ **Note:** To convert between decibel and linear energy (like most volume sliders do), use :ref:`@GlobalScope.db_to_linear<class_@GlobalScope_method_db_to_linear>` and :ref:`@GlobalScope.linear_to_db<class_@GlobalScope_method_linear_to_db>`.
|
|
|
|
|
|
.. rst-class:: classref-section-separator
|
|
|
|
|
@@ -323,7 +329,9 @@ Method Descriptions
|
|
|
|
|
|
:ref:`float<class_float>` **get_playback_position**\ (\ )
|
|
|
|
|
|
-Returns the position in the :ref:`AudioStream<class_AudioStream>` in seconds.
|
|
|
+Returns the position in the :ref:`AudioStream<class_AudioStream>` of the latest sound, in seconds. Returns ``0.0`` if no sounds are playing.
|
|
|
+
|
|
|
+\ **Note:** The position is not always accurate, as the :ref:`AudioServer<class_AudioServer>` does not mix audio every processed frame. To get more accurate results, add :ref:`AudioServer.get_time_since_last_mix<class_AudioServer_method_get_time_since_last_mix>` to the returned position.
|
|
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
|
@@ -335,7 +343,7 @@ Returns the position in the :ref:`AudioStream<class_AudioStream>` in seconds.
|
|
|
|
|
|
:ref:`AudioStreamPlayback<class_AudioStreamPlayback>` **get_stream_playback**\ (\ )
|
|
|
|
|
|
-Returns the :ref:`AudioStreamPlayback<class_AudioStreamPlayback>` object associated with this **AudioStreamPlayer**.
|
|
|
+Returns the latest :ref:`AudioStreamPlayback<class_AudioStreamPlayback>` of this node, usually the most recently created by :ref:`play<class_AudioStreamPlayer_method_play>`. If no sounds are playing, this method fails and returns an empty playback.
|
|
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
|
@@ -347,7 +355,7 @@ Returns the :ref:`AudioStreamPlayback<class_AudioStreamPlayback>` object associa
|
|
|
|
|
|
:ref:`bool<class_bool>` **has_stream_playback**\ (\ )
|
|
|
|
|
|
-Returns whether the **AudioStreamPlayer** can return the :ref:`AudioStreamPlayback<class_AudioStreamPlayback>` object or not.
|
|
|
+Returns ``true`` if any sound is active, even if :ref:`stream_paused<class_AudioStreamPlayer_property_stream_paused>` is set to ``true``. See also :ref:`playing<class_AudioStreamPlayer_property_playing>` and :ref:`get_stream_playback<class_AudioStreamPlayer_method_get_stream_playback>`.
|
|
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
|
@@ -359,7 +367,7 @@ Returns whether the **AudioStreamPlayer** can return the :ref:`AudioStreamPlayba
|
|
|
|
|
|
|void| **play**\ (\ from_position\: :ref:`float<class_float>` = 0.0\ )
|
|
|
|
|
|
-Plays the audio from the given ``from_position``, in seconds.
|
|
|
+Plays a sound from the beginning, or the given ``from_position`` in seconds.
|
|
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
|
@@ -371,7 +379,7 @@ Plays the audio from the given ``from_position``, in seconds.
|
|
|
|
|
|
|void| **seek**\ (\ to_position\: :ref:`float<class_float>`\ )
|
|
|
|
|
|
-Sets the position from which audio will be played, in seconds.
|
|
|
+Restarts all sounds to be played from the given ``to_position``, in seconds. Does nothing if no sounds are playing.
|
|
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
|
@@ -383,7 +391,7 @@ Sets the position from which audio will be played, in seconds.
|
|
|
|
|
|
|void| **stop**\ (\ )
|
|
|
|
|
|
-Stops the audio.
|
|
|
+Stops all sounds from this node.
|
|
|
|
|
|
.. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
|
|
|
.. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
|