Search code examples
javaslick2d

How to play sound and music in slick2D java gaming library?


I am developing a 2D game in java slick2D.

The game works fine and there are no errors. But not if I try to play sound and music.

Anyway I was not able to play.

Here is my code:

 @Override
        public void init(GameContainer gc,StateBasedGame sbg) throws SlickException{
            sound=new Sound("sounds/town.wav");
            sound.play(1f, 1f);
            sound.play();
        }

And I have used jogg-0.0.7.jar, jorbis-0.0.17-1.jar, jorbis-0.0.15-1.jar.

There are no any errors but the sound is not playing.

Can you please give me a solution?

Thanks.


Solution

  • i am posting this for others who looking for a answer for this situation. in windows : i just changed the library location to outside the project. then it worked after resetting the library path from project properties.but in linux it worked fine without doing anything. i suggest you to change your library location to outside the project if you are sure you have added all the libraries correctly and getting some errors.