LWJGL OpenAL sound repeating on beginning bit

Hi,

I am trying to play music on my title screen, however I cant seem to do it properly, the sound just keeps playing the first note over and over. initSound() is being loaded in before everything, and then is used in draw()

	public static Audio titleTheme;

	public static void initSound() {
		try {
			//Load title theme music
		    titleTheme = AudioLoader.getAudio("WAV", ResourceLoader.getResourceAsStream("res/sound/Title Theme.wav"));
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	   public void draw() {
		   // first two arguments are pitch and gain, the boolean is whether to loop the content
		   titleTheme.playAsMusic(1.0f, 1.0f, true);

	}

I havent used OpenAL/Slick-Util music before so please excuse my ignorance.
Thank you,

  • Dan

Draw getting called every frame?

If so, problem spotted.

I will give more detail, if you are calling playAsMusic each frame or loop iteration, it just constantly starts over. You need to add a timer in there that loops it, or if there is a loop setting use it and call the play one in the constructor.

Where should I put it so that its still in the gamestate, but not being called every second?

Thanks,

  • Dan

Read post above, you just need to call it once and then loop it, using a timer or a boolean. If audio has a field like isPlaying, a simple if not statement in the loop will do it

Yeah, thats what the true boolean is doing, but where should I call it once? if I call it anywhere it will play the whole time?

Thanks,

  • Dan

Constructor? Depends how your game is coded, but generally you will call something like MainMenu main = new MainMenu(); which inits your menu or game, whatever.

Should not have to explain the rest, if so consider revising Lol.