1
\$\begingroup\$

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?

\$\endgroup\$
  • 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 '17 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\$ – Storm Apr 20 '17 at 16:05
2
\$\begingroup\$

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();

        }
    });
\$\endgroup\$
  • \$\begingroup\$ Ended up using this method; although this is just a workaround, I think libgdx must have a patch for this issue. \$\endgroup\$ – Storm May 3 '17 at 5:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.