Signal on "Sample playing ended" on base SamplePlayer

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

Hi is there a way to listen to a sound finishing playing?, and then executing a callback?. I was looking for some signal to connect to, but i couldn’t find it.

If there isn’t would doing something like this be good?

var started_playing
var last_sound

func _ready():
   started_playing = false;
   MySampler.add_user_signal("sound_finished", [{"sound": TYPE_STRING}]);

func play_sound(key):;
   started_playing = true;
   last_sound = key;

func _process(delta):
   if(!MySampler.is_active() && started_playing):
      emit("sound_finished", last_sound);
      started_playing = false;

Might have some syntax errors couse i wrote it directly here, but asking if the generla idea es correct and any who has experience in this feel free to advise me, thanks!.

:bust_in_silhouette: Reply From: two_headed_goblin

Hi, i used the code and it works perfectly.

I had to add a timer with a wait time of 0.2 to support the case where you fire a sound immediately after one has finished, which is pretty rare in my game but wanted to have that working nonetheless. This is the final version i’m using:

And this is a client using this enchcanced SamplePlayer, it starts to repro “sound2” after “sound1” finishes.

Made this repo with my sandbox for testing this if you want to download it feel free to do so. Happy Coding! :slight_smile: