Search code examples
javaaudiolibgdxplayback

why i can't play the full song on libgdx


I have this sound track and I can't play it all. It always plays first of track like 5 seconds and then stops. It should be 63 seconds.

Sound sound;
@Override
public void create() { 
  soundback=Gdx.audio.newSound(Gdx.files.internal("background.wav"));
  soundback.play();
}

Solution

  • The libgdx Sound class is for small sounds that are used many times even at the same time over each other. Music however, is for longer sounds that only play one at a time like the song in the background.

    Music music = Gdx.audio.newMusic(Gdx.files.internal("data/mymusic.mp3"));
    music.play();