I have this code to play music (found online):
import java.applet.Applet;
import java.applet.AudioClip;
import java.net.URL;
public class MusicBackground {
public static void main(String[] args) throws Exception {
URL url = MusicBackground.class.getResource("backgroundMusic.wav");
AudioClip clip = Applet.newAudioClip(url);
clip.play();
Thread.sleep(1000);
clip.loop();
}
}
It works fine alone. But the thing is that after I implemented it into my game, it either plays the music when I'm launching the music class, or when I run the entire game, it runs the game without the music. Here is my Boot class for my game:
import static helpers.Artist.BeginSession;
import org.lwjgl.opengl.Display;
import helpers.Clock;
import helpers.StateManager;
public class Boot {
public Boot() {
//Call static method in Artist class to initialize OpenGL calls
BeginSession();
//Main game loop
while (!Display.isCloseRequested()) {
Clock.update();
StateManager.update();
Display.update();
Display.sync(60);
}
Display.destroy();
}
public static void main(String[] args) {
new Boot();
}
}
I know that the music background class is in public static void main. But how do I implement it into the boot class ?