:github_url: hide .. meta:: :keywords: sound, music, song .. _class_AudioStreamPlayer: AudioStreamPlayer ================= **Hereda:** :ref:`Node` **<** :ref:`Object` Un nodo para la reproducción de audio. .. rst-class:: classref-introduction-group Descripción ---------------------- The **AudioStreamPlayer** node plays an audio stream non-positionally. It is ideal for user interfaces, menus, or background music. To use this node, :ref:`stream` needs to be set to a valid :ref:`AudioStream` resource. Playing more than one sound at the same time is also supported, see :ref:`max_polyphony`. If you need to play audio at a specific position, use :ref:`AudioStreamPlayer2D` or :ref:`AudioStreamPlayer3D` instead. .. rst-class:: classref-introduction-group Tutoriales -------------------- - :doc:`Corriente de Audio <../tutorials/audio/audio_streams>` - `Demo de Dodge The Creeps en 2D `__ - `Demo del Cambiador de Dispositivos de Audio `__ - `Demo de Generador de Audio `__ - `Demo de Grabación de Audio con Micrófono `__ - `Demo de Visualizador de Espectro de Audio `__ .. rst-class:: classref-reftable-group Propiedades ---------------------- .. table:: :widths: auto +----------------------------------------------------+----------------------------------------------------------------------+---------------+ | :ref:`bool` | :ref:`autoplay` | ``false`` | +----------------------------------------------------+----------------------------------------------------------------------+---------------+ | :ref:`StringName` | :ref:`bus` | ``&"Master"`` | +----------------------------------------------------+----------------------------------------------------------------------+---------------+ | :ref:`int` | :ref:`max_polyphony` | ``1`` | +----------------------------------------------------+----------------------------------------------------------------------+---------------+ | :ref:`MixTarget` | :ref:`mix_target` | ``0`` | +----------------------------------------------------+----------------------------------------------------------------------+---------------+ | :ref:`float` | :ref:`pitch_scale` | ``1.0`` | +----------------------------------------------------+----------------------------------------------------------------------+---------------+ | :ref:`PlaybackType` | :ref:`playback_type` | ``0`` | +----------------------------------------------------+----------------------------------------------------------------------+---------------+ | :ref:`bool` | :ref:`playing` | ``false`` | +----------------------------------------------------+----------------------------------------------------------------------+---------------+ | :ref:`AudioStream` | :ref:`stream` | | +----------------------------------------------------+----------------------------------------------------------------------+---------------+ | :ref:`bool` | :ref:`stream_paused` | ``false`` | +----------------------------------------------------+----------------------------------------------------------------------+---------------+ | :ref:`float` | :ref:`volume_db` | ``0.0`` | +----------------------------------------------------+----------------------------------------------------------------------+---------------+ | :ref:`float` | :ref:`volume_linear` | | +----------------------------------------------------+----------------------------------------------------------------------+---------------+ .. rst-class:: classref-reftable-group Métodos -------------- .. table:: :widths: auto +-------------------------------------------------------+---------------------------------------------------------------------------------------------------------+ | :ref:`float` | :ref:`get_playback_position`\ (\ ) | +-------------------------------------------------------+---------------------------------------------------------------------------------------------------------+ | :ref:`AudioStreamPlayback` | :ref:`get_stream_playback`\ (\ ) | +-------------------------------------------------------+---------------------------------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`has_stream_playback`\ (\ ) | +-------------------------------------------------------+---------------------------------------------------------------------------------------------------------+ | |void| | :ref:`play`\ (\ from_position\: :ref:`float` = 0.0\ ) | +-------------------------------------------------------+---------------------------------------------------------------------------------------------------------+ | |void| | :ref:`seek`\ (\ to_position\: :ref:`float`\ ) | +-------------------------------------------------------+---------------------------------------------------------------------------------------------------------+ | |void| | :ref:`stop`\ (\ ) | +-------------------------------------------------------+---------------------------------------------------------------------------------------------------------+ .. rst-class:: classref-section-separator ---- .. rst-class:: classref-descriptions-group Señales -------------- .. _class_AudioStreamPlayer_signal_finished: .. rst-class:: classref-signal **finished**\ (\ ) :ref:`🔗` Emitted when a sound finishes playing without interruptions. This signal is *not* emitted when calling :ref:`stop()`, or when exiting the tree while sounds are playing. .. rst-class:: classref-section-separator ---- .. rst-class:: classref-descriptions-group Enumeraciones -------------------------- .. _enum_AudioStreamPlayer_MixTarget: .. rst-class:: classref-enumeration enum **MixTarget**: :ref:`🔗` .. _class_AudioStreamPlayer_constant_MIX_TARGET_STEREO: .. rst-class:: classref-enumeration-constant :ref:`MixTarget` **MIX_TARGET_STEREO** = ``0`` The audio will be played only on the first channel. This is the default. .. _class_AudioStreamPlayer_constant_MIX_TARGET_SURROUND: .. rst-class:: classref-enumeration-constant :ref:`MixTarget` **MIX_TARGET_SURROUND** = ``1`` El audio se reproducirá en todos los canales de sonido envolvente. .. _class_AudioStreamPlayer_constant_MIX_TARGET_CENTER: .. rst-class:: classref-enumeration-constant :ref:`MixTarget` **MIX_TARGET_CENTER** = ``2`` El audio se reproducirá en el segundo canal, que suele ser el del centro. .. rst-class:: classref-section-separator ---- .. rst-class:: classref-descriptions-group Descripciones de Propiedades -------------------------------------------------------- .. _class_AudioStreamPlayer_property_autoplay: .. rst-class:: classref-property :ref:`bool` **autoplay** = ``false`` :ref:`🔗` .. rst-class:: classref-property-setget - |void| **set_autoplay**\ (\ value\: :ref:`bool`\ ) - :ref:`bool` **is_autoplay_enabled**\ (\ ) If ``true``, this node calls :ref:`play()` when entering the tree. .. rst-class:: classref-item-separator ---- .. _class_AudioStreamPlayer_property_bus: .. rst-class:: classref-property :ref:`StringName` **bus** = ``&"Master"`` :ref:`🔗` .. rst-class:: classref-property-setget - |void| **set_bus**\ (\ value\: :ref:`StringName`\ ) - :ref:`StringName` **get_bus**\ (\ ) 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 :ref:`AudioServer.get_bus_name()`. .. rst-class:: classref-item-separator ---- .. _class_AudioStreamPlayer_property_max_polyphony: .. rst-class:: classref-property :ref:`int` **max_polyphony** = ``1`` :ref:`🔗` .. rst-class:: classref-property-setget - |void| **set_max_polyphony**\ (\ value\: :ref:`int`\ ) - :ref:`int` **get_max_polyphony**\ (\ ) El número máximo de sonidos que este nodo puede reproducir simultáneamente. Al llamar a :ref:`play()` después de alcanzar este valor, se eliminarán los sonidos más antiguos. .. rst-class:: classref-item-separator ---- .. _class_AudioStreamPlayer_property_mix_target: .. rst-class:: classref-property :ref:`MixTarget` **mix_target** = ``0`` :ref:`🔗` .. rst-class:: classref-property-setget - |void| **set_mix_target**\ (\ value\: :ref:`MixTarget`\ ) - :ref:`MixTarget` **get_mix_target**\ (\ ) The mix target channels. Has no effect when two speakers or less are detected (see :ref:`SpeakerMode`). .. rst-class:: classref-item-separator ---- .. _class_AudioStreamPlayer_property_pitch_scale: .. rst-class:: classref-property :ref:`float` **pitch_scale** = ``1.0`` :ref:`🔗` .. rst-class:: classref-property-setget - |void| **set_pitch_scale**\ (\ value\: :ref:`float`\ ) - :ref:`float` **get_pitch_scale**\ (\ ) The audio's pitch and tempo, as a multiplier of the :ref:`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 ---- .. _class_AudioStreamPlayer_property_playback_type: .. rst-class:: classref-property :ref:`PlaybackType` **playback_type** = ``0`` :ref:`🔗` .. rst-class:: classref-property-setget - |void| **set_playback_type**\ (\ value\: :ref:`PlaybackType`\ ) - :ref:`PlaybackType` **get_playback_type**\ (\ ) **Experimental:** Esta propiedad podría ser modificada o eliminada en versiones futuras. The playback type of the stream player. If set other than to the default value, it will force that playback type. .. rst-class:: classref-item-separator ---- .. _class_AudioStreamPlayer_property_playing: .. rst-class:: classref-property :ref:`bool` **playing** = ``false`` :ref:`🔗` .. rst-class:: classref-property-setget - |void| **set_playing**\ (\ value\: :ref:`bool`\ ) - :ref:`bool` **is_playing**\ (\ ) If ``true``, this node is playing sounds. Setting this property has the same effect as :ref:`play()` and :ref:`stop()`. .. rst-class:: classref-item-separator ---- .. _class_AudioStreamPlayer_property_stream: .. rst-class:: classref-property :ref:`AudioStream` **stream** :ref:`🔗` .. rst-class:: classref-property-setget - |void| **set_stream**\ (\ value\: :ref:`AudioStream`\ ) - :ref:`AudioStream` **get_stream**\ (\ ) El recurso :ref:`AudioStream` que se reproducirá. Al configurar esta propiedad, se detendrán todos los sonidos que se estén reproduciendo. Si se deja vacía, **AudioStreamPlayer** no funcionará. .. rst-class:: classref-item-separator ---- .. _class_AudioStreamPlayer_property_stream_paused: .. rst-class:: classref-property :ref:`bool` **stream_paused** = ``false`` :ref:`🔗` .. rst-class:: classref-property-setget - |void| **set_stream_paused**\ (\ value\: :ref:`bool`\ ) - :ref:`bool` **get_stream_paused**\ (\ ) If ``true``, the sounds are paused. Setting :ref:`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`). .. rst-class:: classref-item-separator ---- .. _class_AudioStreamPlayer_property_volume_db: .. rst-class:: classref-property :ref:`float` **volume_db** = ``0.0`` :ref:`🔗` .. rst-class:: classref-property-setget - |void| **set_volume_db**\ (\ value\: :ref:`float`\ ) - :ref:`float` **get_volume_db**\ (\ ) Volume of sound, in decibels. This is an offset of the :ref:`stream`'s volume. \ **Note:** To convert between decibel and linear energy (like most volume sliders do), use :ref:`volume_linear`, or :ref:`@GlobalScope.db_to_linear()` and :ref:`@GlobalScope.linear_to_db()`. .. rst-class:: classref-item-separator ---- .. _class_AudioStreamPlayer_property_volume_linear: .. rst-class:: classref-property :ref:`float` **volume_linear** :ref:`🔗` .. rst-class:: classref-property-setget - |void| **set_volume_linear**\ (\ value\: :ref:`float`\ ) - :ref:`float` **get_volume_linear**\ (\ ) Volume of sound, as a linear value. \ **Note:** This member modifies :ref:`volume_db` for convenience. The returned value is equivalent to the result of :ref:`@GlobalScope.db_to_linear()` on :ref:`volume_db`. Setting this member is equivalent to setting :ref:`volume_db` to the result of :ref:`@GlobalScope.linear_to_db()` on a value. .. rst-class:: classref-section-separator ---- .. rst-class:: classref-descriptions-group Descripciones de Métodos ------------------------------------------------ .. _class_AudioStreamPlayer_method_get_playback_position: .. rst-class:: classref-method :ref:`float` **get_playback_position**\ (\ ) :ref:`🔗` Returns the position in the :ref:`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` does not mix audio every processed frame. To get more accurate results, add :ref:`AudioServer.get_time_since_last_mix()` to the returned position. \ **Note:** This method always returns ``0.0`` if the :ref:`stream` is an :ref:`AudioStreamInteractive`, since it can have multiple clips playing at once. .. rst-class:: classref-item-separator ---- .. _class_AudioStreamPlayer_method_get_stream_playback: .. rst-class:: classref-method :ref:`AudioStreamPlayback` **get_stream_playback**\ (\ ) :ref:`🔗` Returns the latest :ref:`AudioStreamPlayback` of this node, usually the most recently created by :ref:`play()`. If no sounds are playing, this method fails and returns an empty playback. .. rst-class:: classref-item-separator ---- .. _class_AudioStreamPlayer_method_has_stream_playback: .. rst-class:: classref-method :ref:`bool` **has_stream_playback**\ (\ ) :ref:`🔗` Returns ``true`` if any sound is active, even if :ref:`stream_paused` is set to ``true``. See also :ref:`playing` and :ref:`get_stream_playback()`. .. rst-class:: classref-item-separator ---- .. _class_AudioStreamPlayer_method_play: .. rst-class:: classref-method |void| **play**\ (\ from_position\: :ref:`float` = 0.0\ ) :ref:`🔗` Plays a sound from the beginning, or the given ``from_position`` in seconds. .. rst-class:: classref-item-separator ---- .. _class_AudioStreamPlayer_method_seek: .. rst-class:: classref-method |void| **seek**\ (\ to_position\: :ref:`float`\ ) :ref:`🔗` Reinicia todos los sonidos que se reproducirán desde el ``to_position`` indicado, en segundos. No hace nada si no se reproduce ningún sonido. .. rst-class:: classref-item-separator ---- .. _class_AudioStreamPlayer_method_stop: .. rst-class:: classref-method |void| **stop**\ (\ ) :ref:`🔗` Stops all sounds from this node. .. |virtual| replace:: :abbr:`virtual (Normalmente, este método debería ser sobreescrito por el usuario para que tenga algún efecto.)` .. |required| replace:: :abbr:`required (This method is required to be overridden when extending its base class.)` .. |const| replace:: :abbr:`const (Este método no tiene efectos secundarios. No modifica ninguna de las variables miembro de la instancia.)` .. |vararg| replace:: :abbr:`vararg (Este método permite agregar cualquier número de argumentos después de los descritos aquí.)` .. |constructor| replace:: :abbr:`constructor (Este método se utiliza para construir un tipo.)` .. |static| replace:: :abbr:`static (Este método no necesita una instancia para ser llamado, por lo que puede llamarse directamente utilizando el nombre de la clase.)` .. |operator| replace:: :abbr:`operator (Este método describe un operador válido para usar con este tipo como operando izquierdo.)` .. |bitfield| replace:: :abbr:`BitField (Este valor es un entero compuesto como una máscara de bits de las siguientes banderas.)` .. |void| replace:: :abbr:`void (Sin valor de retorno.)`