class_audiostreamplayer.rst 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  1. :github_url: hide
  2. .. meta::
  3. :keywords: sound, music, song
  4. .. DO NOT EDIT THIS FILE!!!
  5. .. Generated automatically from Godot engine sources.
  6. .. Generator: https://github.com/godotengine/godot/tree/master/doc/tools/make_rst.py.
  7. .. XML source: https://github.com/godotengine/godot/tree/master/doc/classes/AudioStreamPlayer.xml.
  8. .. _class_AudioStreamPlayer:
  9. AudioStreamPlayer
  10. =================
  11. **Inherits:** :ref:`Node<class_Node>` **<** :ref:`Object<class_Object>`
  12. A node for audio playback.
  13. .. rst-class:: classref-introduction-group
  14. Description
  15. -----------
  16. The **AudioStreamPlayer** node plays an audio stream non-positionally. It is ideal for user interfaces, menus, or background music.
  17. 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 same time is also supported, see :ref:`max_polyphony<class_AudioStreamPlayer_property_max_polyphony>`.
  18. If you need to play audio at a specific position, use :ref:`AudioStreamPlayer2D<class_AudioStreamPlayer2D>` or :ref:`AudioStreamPlayer3D<class_AudioStreamPlayer3D>` instead.
  19. .. rst-class:: classref-introduction-group
  20. Tutorials
  21. ---------
  22. - :doc:`Audio streams <../tutorials/audio/audio_streams>`
  23. - `2D Dodge The Creeps Demo <https://godotengine.org/asset-library/asset/2712>`__
  24. - `Audio Device Changer Demo <https://godotengine.org/asset-library/asset/2758>`__
  25. - `Audio Generator Demo <https://godotengine.org/asset-library/asset/2759>`__
  26. - `Audio Microphone Record Demo <https://godotengine.org/asset-library/asset/2760>`__
  27. - `Audio Spectrum Visualizer Demo <https://godotengine.org/asset-library/asset/2762>`__
  28. .. rst-class:: classref-reftable-group
  29. Properties
  30. ----------
  31. .. table::
  32. :widths: auto
  33. +----------------------------------------------------+----------------------------------------------------------------------+---------------+
  34. | :ref:`bool<class_bool>` | :ref:`autoplay<class_AudioStreamPlayer_property_autoplay>` | ``false`` |
  35. +----------------------------------------------------+----------------------------------------------------------------------+---------------+
  36. | :ref:`StringName<class_StringName>` | :ref:`bus<class_AudioStreamPlayer_property_bus>` | ``&"Master"`` |
  37. +----------------------------------------------------+----------------------------------------------------------------------+---------------+
  38. | :ref:`int<class_int>` | :ref:`max_polyphony<class_AudioStreamPlayer_property_max_polyphony>` | ``1`` |
  39. +----------------------------------------------------+----------------------------------------------------------------------+---------------+
  40. | :ref:`MixTarget<enum_AudioStreamPlayer_MixTarget>` | :ref:`mix_target<class_AudioStreamPlayer_property_mix_target>` | ``0`` |
  41. +----------------------------------------------------+----------------------------------------------------------------------+---------------+
  42. | :ref:`float<class_float>` | :ref:`pitch_scale<class_AudioStreamPlayer_property_pitch_scale>` | ``1.0`` |
  43. +----------------------------------------------------+----------------------------------------------------------------------+---------------+
  44. | :ref:`PlaybackType<enum_AudioServer_PlaybackType>` | :ref:`playback_type<class_AudioStreamPlayer_property_playback_type>` | ``0`` |
  45. +----------------------------------------------------+----------------------------------------------------------------------+---------------+
  46. | :ref:`bool<class_bool>` | :ref:`playing<class_AudioStreamPlayer_property_playing>` | ``false`` |
  47. +----------------------------------------------------+----------------------------------------------------------------------+---------------+
  48. | :ref:`AudioStream<class_AudioStream>` | :ref:`stream<class_AudioStreamPlayer_property_stream>` | |
  49. +----------------------------------------------------+----------------------------------------------------------------------+---------------+
  50. | :ref:`bool<class_bool>` | :ref:`stream_paused<class_AudioStreamPlayer_property_stream_paused>` | ``false`` |
  51. +----------------------------------------------------+----------------------------------------------------------------------+---------------+
  52. | :ref:`float<class_float>` | :ref:`volume_db<class_AudioStreamPlayer_property_volume_db>` | ``0.0`` |
  53. +----------------------------------------------------+----------------------------------------------------------------------+---------------+
  54. | :ref:`float<class_float>` | :ref:`volume_linear<class_AudioStreamPlayer_property_volume_linear>` | |
  55. +----------------------------------------------------+----------------------------------------------------------------------+---------------+
  56. .. rst-class:: classref-reftable-group
  57. Methods
  58. -------
  59. .. table::
  60. :widths: auto
  61. +-------------------------------------------------------+---------------------------------------------------------------------------------------------------------+
  62. | :ref:`float<class_float>` | :ref:`get_playback_position<class_AudioStreamPlayer_method_get_playback_position>`\ (\ ) |
  63. +-------------------------------------------------------+---------------------------------------------------------------------------------------------------------+
  64. | :ref:`AudioStreamPlayback<class_AudioStreamPlayback>` | :ref:`get_stream_playback<class_AudioStreamPlayer_method_get_stream_playback>`\ (\ ) |
  65. +-------------------------------------------------------+---------------------------------------------------------------------------------------------------------+
  66. | :ref:`bool<class_bool>` | :ref:`has_stream_playback<class_AudioStreamPlayer_method_has_stream_playback>`\ (\ ) |
  67. +-------------------------------------------------------+---------------------------------------------------------------------------------------------------------+
  68. | |void| | :ref:`play<class_AudioStreamPlayer_method_play>`\ (\ from_position\: :ref:`float<class_float>` = 0.0\ ) |
  69. +-------------------------------------------------------+---------------------------------------------------------------------------------------------------------+
  70. | |void| | :ref:`seek<class_AudioStreamPlayer_method_seek>`\ (\ to_position\: :ref:`float<class_float>`\ ) |
  71. +-------------------------------------------------------+---------------------------------------------------------------------------------------------------------+
  72. | |void| | :ref:`stop<class_AudioStreamPlayer_method_stop>`\ (\ ) |
  73. +-------------------------------------------------------+---------------------------------------------------------------------------------------------------------+
  74. .. rst-class:: classref-section-separator
  75. ----
  76. .. rst-class:: classref-descriptions-group
  77. Signals
  78. -------
  79. .. _class_AudioStreamPlayer_signal_finished:
  80. .. rst-class:: classref-signal
  81. **finished**\ (\ ) :ref:`🔗<class_AudioStreamPlayer_signal_finished>`
  82. 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.
  83. .. rst-class:: classref-section-separator
  84. ----
  85. .. rst-class:: classref-descriptions-group
  86. Enumerations
  87. ------------
  88. .. _enum_AudioStreamPlayer_MixTarget:
  89. .. rst-class:: classref-enumeration
  90. enum **MixTarget**: :ref:`🔗<enum_AudioStreamPlayer_MixTarget>`
  91. .. _class_AudioStreamPlayer_constant_MIX_TARGET_STEREO:
  92. .. rst-class:: classref-enumeration-constant
  93. :ref:`MixTarget<enum_AudioStreamPlayer_MixTarget>` **MIX_TARGET_STEREO** = ``0``
  94. The audio will be played only on the first channel. This is the default.
  95. .. _class_AudioStreamPlayer_constant_MIX_TARGET_SURROUND:
  96. .. rst-class:: classref-enumeration-constant
  97. :ref:`MixTarget<enum_AudioStreamPlayer_MixTarget>` **MIX_TARGET_SURROUND** = ``1``
  98. The audio will be played on all surround channels.
  99. .. _class_AudioStreamPlayer_constant_MIX_TARGET_CENTER:
  100. .. rst-class:: classref-enumeration-constant
  101. :ref:`MixTarget<enum_AudioStreamPlayer_MixTarget>` **MIX_TARGET_CENTER** = ``2``
  102. The audio will be played on the second channel, which is usually the center.
  103. .. rst-class:: classref-section-separator
  104. ----
  105. .. rst-class:: classref-descriptions-group
  106. Property Descriptions
  107. ---------------------
  108. .. _class_AudioStreamPlayer_property_autoplay:
  109. .. rst-class:: classref-property
  110. :ref:`bool<class_bool>` **autoplay** = ``false`` :ref:`🔗<class_AudioStreamPlayer_property_autoplay>`
  111. .. rst-class:: classref-property-setget
  112. - |void| **set_autoplay**\ (\ value\: :ref:`bool<class_bool>`\ )
  113. - :ref:`bool<class_bool>` **is_autoplay_enabled**\ (\ )
  114. If ``true``, this node calls :ref:`play()<class_AudioStreamPlayer_method_play>` when entering the tree.
  115. .. rst-class:: classref-item-separator
  116. ----
  117. .. _class_AudioStreamPlayer_property_bus:
  118. .. rst-class:: classref-property
  119. :ref:`StringName<class_StringName>` **bus** = ``&"Master"`` :ref:`🔗<class_AudioStreamPlayer_property_bus>`
  120. .. rst-class:: classref-property-setget
  121. - |void| **set_bus**\ (\ value\: :ref:`StringName<class_StringName>`\ )
  122. - :ref:`StringName<class_StringName>` **get_bus**\ (\ )
  123. The target bus name. All sounds from this node will be playing on this bus.
  124. \ **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>`.
  125. .. rst-class:: classref-item-separator
  126. ----
  127. .. _class_AudioStreamPlayer_property_max_polyphony:
  128. .. rst-class:: classref-property
  129. :ref:`int<class_int>` **max_polyphony** = ``1`` :ref:`🔗<class_AudioStreamPlayer_property_max_polyphony>`
  130. .. rst-class:: classref-property-setget
  131. - |void| **set_max_polyphony**\ (\ value\: :ref:`int<class_int>`\ )
  132. - :ref:`int<class_int>` **get_max_polyphony**\ (\ )
  133. 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.
  134. .. rst-class:: classref-item-separator
  135. ----
  136. .. _class_AudioStreamPlayer_property_mix_target:
  137. .. rst-class:: classref-property
  138. :ref:`MixTarget<enum_AudioStreamPlayer_MixTarget>` **mix_target** = ``0`` :ref:`🔗<class_AudioStreamPlayer_property_mix_target>`
  139. .. rst-class:: classref-property-setget
  140. - |void| **set_mix_target**\ (\ value\: :ref:`MixTarget<enum_AudioStreamPlayer_MixTarget>`\ )
  141. - :ref:`MixTarget<enum_AudioStreamPlayer_MixTarget>` **get_mix_target**\ (\ )
  142. 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>`).
  143. .. rst-class:: classref-item-separator
  144. ----
  145. .. _class_AudioStreamPlayer_property_pitch_scale:
  146. .. rst-class:: classref-property
  147. :ref:`float<class_float>` **pitch_scale** = ``1.0`` :ref:`🔗<class_AudioStreamPlayer_property_pitch_scale>`
  148. .. rst-class:: classref-property-setget
  149. - |void| **set_pitch_scale**\ (\ value\: :ref:`float<class_float>`\ )
  150. - :ref:`float<class_float>` **get_pitch_scale**\ (\ )
  151. 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.
  152. .. rst-class:: classref-item-separator
  153. ----
  154. .. _class_AudioStreamPlayer_property_playback_type:
  155. .. rst-class:: classref-property
  156. :ref:`PlaybackType<enum_AudioServer_PlaybackType>` **playback_type** = ``0`` :ref:`🔗<class_AudioStreamPlayer_property_playback_type>`
  157. .. rst-class:: classref-property-setget
  158. - |void| **set_playback_type**\ (\ value\: :ref:`PlaybackType<enum_AudioServer_PlaybackType>`\ )
  159. - :ref:`PlaybackType<enum_AudioServer_PlaybackType>` **get_playback_type**\ (\ )
  160. **Experimental:** This property may be changed or removed in future versions.
  161. The playback type of the stream player. If set other than to the default value, it will force that playback type.
  162. .. rst-class:: classref-item-separator
  163. ----
  164. .. _class_AudioStreamPlayer_property_playing:
  165. .. rst-class:: classref-property
  166. :ref:`bool<class_bool>` **playing** = ``false`` :ref:`🔗<class_AudioStreamPlayer_property_playing>`
  167. .. rst-class:: classref-property-setget
  168. - |void| **set_playing**\ (\ value\: :ref:`bool<class_bool>`\ )
  169. - :ref:`bool<class_bool>` **is_playing**\ (\ )
  170. 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>`.
  171. .. rst-class:: classref-item-separator
  172. ----
  173. .. _class_AudioStreamPlayer_property_stream:
  174. .. rst-class:: classref-property
  175. :ref:`AudioStream<class_AudioStream>` **stream** :ref:`🔗<class_AudioStreamPlayer_property_stream>`
  176. .. rst-class:: classref-property-setget
  177. - |void| **set_stream**\ (\ value\: :ref:`AudioStream<class_AudioStream>`\ )
  178. - :ref:`AudioStream<class_AudioStream>` **get_stream**\ (\ )
  179. 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.
  180. .. rst-class:: classref-item-separator
  181. ----
  182. .. _class_AudioStreamPlayer_property_stream_paused:
  183. .. rst-class:: classref-property
  184. :ref:`bool<class_bool>` **stream_paused** = ``false`` :ref:`🔗<class_AudioStreamPlayer_property_stream_paused>`
  185. .. rst-class:: classref-property-setget
  186. - |void| **set_stream_paused**\ (\ value\: :ref:`bool<class_bool>`\ )
  187. - :ref:`bool<class_bool>` **get_stream_paused**\ (\ )
  188. If ``true``, the sounds are paused. Setting :ref:`stream_paused<class_AudioStreamPlayer_property_stream_paused>` to ``false`` resumes all sounds.
  189. \ **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>`).
  190. .. rst-class:: classref-item-separator
  191. ----
  192. .. _class_AudioStreamPlayer_property_volume_db:
  193. .. rst-class:: classref-property
  194. :ref:`float<class_float>` **volume_db** = ``0.0`` :ref:`🔗<class_AudioStreamPlayer_property_volume_db>`
  195. .. rst-class:: classref-property-setget
  196. - |void| **set_volume_db**\ (\ value\: :ref:`float<class_float>`\ )
  197. - :ref:`float<class_float>` **get_volume_db**\ (\ )
  198. Volume of sound, in decibels. This is an offset of the :ref:`stream<class_AudioStreamPlayer_property_stream>`'s volume.
  199. \ **Note:** To convert between decibel and linear energy (like most volume sliders do), use :ref:`volume_linear<class_AudioStreamPlayer_property_volume_linear>`, or :ref:`@GlobalScope.db_to_linear()<class_@GlobalScope_method_db_to_linear>` and :ref:`@GlobalScope.linear_to_db()<class_@GlobalScope_method_linear_to_db>`.
  200. .. rst-class:: classref-item-separator
  201. ----
  202. .. _class_AudioStreamPlayer_property_volume_linear:
  203. .. rst-class:: classref-property
  204. :ref:`float<class_float>` **volume_linear** :ref:`🔗<class_AudioStreamPlayer_property_volume_linear>`
  205. .. rst-class:: classref-property-setget
  206. - |void| **set_volume_linear**\ (\ value\: :ref:`float<class_float>`\ )
  207. - :ref:`float<class_float>` **get_volume_linear**\ (\ )
  208. Volume of sound, as a linear value.
  209. \ **Note:** This member modifies :ref:`volume_db<class_AudioStreamPlayer_property_volume_db>` for convenience. The returned value is equivalent to the result of :ref:`@GlobalScope.db_to_linear()<class_@GlobalScope_method_db_to_linear>` on :ref:`volume_db<class_AudioStreamPlayer_property_volume_db>`. Setting this member is equivalent to setting :ref:`volume_db<class_AudioStreamPlayer_property_volume_db>` to the result of :ref:`@GlobalScope.linear_to_db()<class_@GlobalScope_method_linear_to_db>` on a value.
  210. .. rst-class:: classref-section-separator
  211. ----
  212. .. rst-class:: classref-descriptions-group
  213. Method Descriptions
  214. -------------------
  215. .. _class_AudioStreamPlayer_method_get_playback_position:
  216. .. rst-class:: classref-method
  217. :ref:`float<class_float>` **get_playback_position**\ (\ ) :ref:`🔗<class_AudioStreamPlayer_method_get_playback_position>`
  218. Returns the position in the :ref:`AudioStream<class_AudioStream>` of the latest sound, in seconds. Returns ``0.0`` if no sounds are playing.
  219. \ **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.
  220. \ **Note:** This method always returns ``0.0`` if the :ref:`stream<class_AudioStreamPlayer_property_stream>` is an :ref:`AudioStreamInteractive<class_AudioStreamInteractive>`, since it can have multiple clips playing at once.
  221. .. rst-class:: classref-item-separator
  222. ----
  223. .. _class_AudioStreamPlayer_method_get_stream_playback:
  224. .. rst-class:: classref-method
  225. :ref:`AudioStreamPlayback<class_AudioStreamPlayback>` **get_stream_playback**\ (\ ) :ref:`🔗<class_AudioStreamPlayer_method_get_stream_playback>`
  226. 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.
  227. .. rst-class:: classref-item-separator
  228. ----
  229. .. _class_AudioStreamPlayer_method_has_stream_playback:
  230. .. rst-class:: classref-method
  231. :ref:`bool<class_bool>` **has_stream_playback**\ (\ ) :ref:`🔗<class_AudioStreamPlayer_method_has_stream_playback>`
  232. 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>`.
  233. .. rst-class:: classref-item-separator
  234. ----
  235. .. _class_AudioStreamPlayer_method_play:
  236. .. rst-class:: classref-method
  237. |void| **play**\ (\ from_position\: :ref:`float<class_float>` = 0.0\ ) :ref:`🔗<class_AudioStreamPlayer_method_play>`
  238. Plays a sound from the beginning, or the given ``from_position`` in seconds.
  239. .. rst-class:: classref-item-separator
  240. ----
  241. .. _class_AudioStreamPlayer_method_seek:
  242. .. rst-class:: classref-method
  243. |void| **seek**\ (\ to_position\: :ref:`float<class_float>`\ ) :ref:`🔗<class_AudioStreamPlayer_method_seek>`
  244. Restarts all sounds to be played from the given ``to_position``, in seconds. Does nothing if no sounds are playing.
  245. .. rst-class:: classref-item-separator
  246. ----
  247. .. _class_AudioStreamPlayer_method_stop:
  248. .. rst-class:: classref-method
  249. |void| **stop**\ (\ ) :ref:`🔗<class_AudioStreamPlayer_method_stop>`
  250. Stops all sounds from this node.
  251. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  252. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  253. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  254. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  255. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  256. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
  257. .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`
  258. .. |void| replace:: :abbr:`void (No return value.)`