How to loop an audio sample?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Freeman
:warning: Old Version Published before Godot 3 was released.

How to loop an audio sample to play over and over again?

:bust_in_silhouette: Reply From: Freeman

First, when importing the sample, loop option has to be checked.
Then in SampleLibrary where the sound is imported, small pencil icon has to be clicked.

Now, the Inspector tab panel will show and let you set some of the properties of the imported sample.
Loop Format sets how to loop is going to be created:
None - no loop at all.
Forward - from start to the end and again from start to the end.
PingPong - from start to the end then reverse playing from end to the start.

Loop Begin indicates the start point of the loop.
Loop End, the point where loop will end.

After setting Loop Format for example to Forward, Loop Begin to 0 and Loop End to 1000000000, the sample will play from the very beginning to the very end, then when reaching the end will start to play again.

Ok it’s “decades” later now. But in case somebody stumbles upon this via google as I did, I want to mention something ;-):

In Godot 3.x you can set the Loop End to 0 if you want to let the sample loop from end to end (and don’t know the exact length in bytes).

Setting to a very big value like mentioned above won’t work anymore.

wombatstampede | 2019-02-07 08:35

The way I’m making my music loop is to use finished() signal of the AudioStreamPlayer to play() the AudioStreamPlayer.

Ridgeway | 2019-05-29 05:45

Good for music but won’t be fast enough for samples. In 3.1 I now make sure that the samples “Loop” flag is set in the import settings. I also make sure that the loop start&end values are set on the wav file.

wombatstampede | 2019-05-29 06:36

Also, don’t forget to “reimport” the audio after you’ve ticked loop :wink:
This got me for a while

MaxwellDexter | 2020-05-19 05:31

It does still work, and is the only I got it to work for me.

703337 | 2020-08-31 15:05

can you update this for godot 4? there’s no “loop checkbox”. https://i.imgur.com/DLUsdCa.png

carcinocron | 2023-03-25 22:18

That’s because you’re looking at the inspector of the AudioStreamPlayer. You have to look at the import settings of the audio file you want to use.

putper | 2023-06-08 19:31