I've been developing this game for which I need to play two sound instances one after another. Calling them one after another results in overlapping sounds. The issue is there is no way to know if a sound has finished playing, any workarounds anyone has found for this?
-
1\$\begingroup\$ If it's always the same 2 sounds, you can combine them offline and play the single sound file, instead of 2. Or you could add a kind of manifest of all the sounds that are in your game which includes their duration, then when you play the second sound, you get the duration of the first, and you artificially add a delay before playing the second sound. P.S. These are generic tips, I'm not familiar with LibGDX. \$\endgroup\$– Vaillancourt ♦Apr 19, 2017 at 13:28
-
\$\begingroup\$ Umm, actually there are a variety of sounds that I need to play, and I'm considering the manifest approach already, thanks for the suggestion. :) \$\endgroup\$– StormApr 20, 2017 at 16:05
1 Answer
You could load your sound as music and then use the setOnCompletionListener
Music s1 = Gdx.audio.newMusic(Gdx.files.internal("some1.wav"));
Music s2 = Gdx.audio.newMusic(Gdx.files.internal("some2.wav"));
s1.setOnCompletionListener(new Music.OnCompletionListener() {
@Override
public void onCompletion(Music music) {
s2.play();
}
});
-
\$\begingroup\$ Ended up using this method; although this is just a workaround, I think libgdx must have a patch for this issue. \$\endgroup\$– StormMay 3, 2017 at 5:24