+1 vote

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!

Godot version 3.2.3
in Engine by (335 points)

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

1 Answer

+2 votes
Best answer

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

by (274 points)
selected by

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.

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

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.