How to enable / disable an AudioStreamPlayer2D

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By FelixMunoz

I want to create a button that enable / disable sounds. How to do this? The question is not a button, but, about the method on AudioStreamPlayer2D.


:bust_in_silhouette: Reply From: ConnyOnny

According to the documentation there is a member variable playing. You can try to set it to false.

If that doesn’t work you can add a script to the player node and add a method pause and resume where you store the value fromget_plaback_position in your own member variable and stop the playback and on resume you can use the play method with the old playback position as parameter, so it starts at that point.

Thank you, but this does not work.

FelixMunoz | 2018-07-28 00:19

:bust_in_silhouette: Reply From: nonomiyo

yep, as ConnyOnny said, you can use this to mute your sound : (it’s going to stop it though, not just mute it)

get_node("yourAudioStreamPlayer").playing = false

this to mute all sounds :

AudioServer.set_bus_mute(AudioServer.get_bus_index("Master"), true)   

or this to mute all sounds from a specific audio bus :

AudioServer.set_bus_mute(AudioServer.get_bus_index("specificbus"), true)   


AudioServer.set_bus_mute(AudioServer.get_bus_index(“Master”), true)

FelixMunoz | 2018-07-28 01:12

Using this:

get_node("yourAudioStreamPlayer").playing = false

Causes the sound to play when setting to: true. So I am not sure it is a good way of muting sound…

bashan | 2020-03-21 17:06