AudioStreamPlayer tries to replay every frame under _process function.

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

Under func _process(delta): the AudioStreamPlayer replays every frame that results in stuttering. What am I missing to make it play once, fully, every time the condition is met under _process(delta) function?

I use .play() and .stop() to play and stop AudioStreamPlayer. It apparantly toggles play on and off every frame which I want to happen only once.

I appreciate your time!

I also tried $Audio.playing = true, still stuttering.

Suleymanov | 2021-02-23 08:54

:bust_in_silhouette: Reply From: Whalesstate

to make the audio stream play once you can check if not audio_stream.is_playing() then play the sound , but this is not a problem from script , it’s from the sound itself , you need to navigate to the sound file in the file system and then switch to the Import tab and disable loop , by default ogg files will loop so you need to un-check it , also in the audio stream player you may find a loop option [ i don’t remember exactly ] so you can un-check it too

Thank you for the reply!

The problem is not that it loops. It doesn’t. It just tries to start it over every single frame. It’s like the audio should sound like “America”, instead it sounds like this: A… a… a… am… a… am… ame… a… am… a… It doesn’t finish it.

It kind of toggles it on and off every frame when I only asked to .play() or set .playing to true.

Suleymanov | 2021-02-25 16:07

it’s a bad practice to play sounds in the process function , usually sfx plays when an event happens , like when a button or key is pressed or something happens like area entered , you can use signals for that or play the sound in ready when a node entered , if you want to make something happen once in process function you should use an extra member variable of type bool , like sound_whatever_is_playing = false , and in the process function you should do it like if something happened and not sound_whatever_is_playing play the sound and set sound_whatever_is_playing = true and then connect the signal finished from the audio_stream_player2d and when it emits set sound_whatever_is_playing = false

Whalesstate | 2021-02-26 03:04