I Cant enable loop using "AudioStreamPlayer2D"!

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

I Am new to godot engine and to game development in general!
alhamdullah i finished “Your first 2D game” Tutorial (by godot) but at the very last step (the “Finishing up” part) i had to add music to my game (using the given asset “House In a Forest Loop.ogg”) but i’ve noticed that it lasts for only 25 seconds witch is very short and will stop suddenly when players reaches a high score! so i tried to enable loop but lo and behold i cant even enable it!

I have no idea what to do i looked it up and could’nt find a solution! changing the audio format does’nt help either!

anyone knows what i am missing? this is frustrating

:bust_in_silhouette: Reply From: aidave

Another way is to catch the “finished” signal and replay it (edited)

Example:

player.connect("finished", Callable(self,"_on_loop_sound").bind(player))
player.play()

func _on_loop_sound(player):
    player.stream_paused = false
    player.play()

Looping with ogg files works fine (it has been the default for ages). As jgodfrey indicated, you may need to enable looping in the import dialog if looping has been disabled for some reason.

stormreaver | 2023-04-24 15:55

Interesting, I’ve never been able to loop ogg files by default, in v3 or v4… never thought to try the re-import… learnt something new!

aidave | 2023-04-24 16:09

1 Like
:bust_in_silhouette: Reply From: jgodfrey

For the Ogg Vorbis format, you can activate looping in the import dialog itself.

  • Double-click the OGG file to open the Importer dialog
  • Near the top left, check Enable for the Loop property.
  • Click Reimport

That’ll activate the Loop property in the associated AudioStreamPlayer2D.

Thank you! It Work’s Perfectly now

unuselessGamer | 2023-04-24 15:48

2 Likes

Another way that i like to do this is by playing the song again when it get finished!

Here’s an example
First go into your AudioStreamPlayer2d Signals and select finished.
(Sorry i am new user that newly created a Godot account so I cannot give more than 1 Screenshots)
After that connect the signal to your scripts.

Then use $YourAudioStreamNodeName.play()

for example:

Capture1

That’s it!

1 Like

Your approach worked well for my MP3 music. I think it can be a good practice to just use finished signal for looping music for any kind of AudioStreamPlayer node because it makes the whole process format independent.