AudioStreamPlayer.Stop() doesn't always stop the audio.

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

My player uses custom state machines, when enter on running state it execute sfxRun.Play() and when exit the state, execute sfxRun.Stop()

sometimes when you enter the state for a very short time, a few milliseconds, the audio never stops.
sfxRun is an AudioStreamPlayer instance (a wav file in loop mode, but the same happens with ogg) This happens on release and debug builds.

What am I doing wrong?

latest Godot_mono on OSX
Thanks.

EDIT: Same happens with GDScript, here a simple example, the audio loop never stop.

var audio : AudioStreamPlayer

func _ready():
    audio = get_node("audio")

func _input(event):
    if event.is_action_pressed ("testKey"):
        audio.play()
        audio.stop()    
:bust_in_silhouette: Reply From: rahsut

If you’re NOT going to use your audio again after stopping it.

Try doing:

audio.stream_paused = true

If you’re going to use your audio again after stopping, the above code will still work. Just, when you need to use your audio again, do:

audio.stream_paused = false

But what it will do is just “unpause” the audio and it won’t restart the audio from the beginning. Sometimes, just writing audio.play() somehow stops it. (It has happened to me before and for some reason, that worked). If none of those worked, try removing the audio.play() code and see what happens. And if still it doesn’t work, do audio.playing = false/audio.playing = true

Hope this helped :slight_smile: