How to loop music at specific point?

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

I’m working on a Sonic fangame in Godot and I’m using GHZ music as a placeholder. the problem is GHZ music loops at a specific point so how do you loop music at a specific point?

:bust_in_silhouette: Reply From: rossunger

Easy solution: open it in a DAW and splice it to the length you want
medium solution: if you know the exact point at which it loops in seconds, then you can attach a script to the audioStream and on _process check if your AudioStreamPlayer’s get_playback_position ( ) == insert loop time here, and if true, play from startTime…

Can you give me the code? I’m a beginner

Rendangbike | 2022-02-02 14:04

I would not recommend this approach for a beginner! lot’s of things that can go wrong.

It would be a lot easier to use Audacity or Garageband or to cut the audio files to the correct length.

rossunger | 2022-02-02 21:23

:bust_in_silhouette: Reply From: Hyper Sonic

No easy answer in Godot 3.4, but since the feature was added in Godot 4:

Select the audio file and set the Loop Offset in the import settings. To preview the loop, double-click on the audio file to open the importer popup, where you can also set the Offset (in seconds) and move the cursor near the end of the track and play to check that it chains perfectly.

Unfortunately, there is no vertical bar indicator showing the offset position. You cannot define a loop end time either, so you must edit your track so it already ends exactly at the end of the loop.