I'm coding a game in java, and I decided to add music to it. I tried with this code:
URL resource = getClass().getResource("music.mp3");
MediaPlayer a = new MediaPlayer(new Media(resource.toString()));
a.setOnEndOfMedia(new Runnable() {
public void run() {
a.seek(Duration.ZERO);
}
});
a.play();
But for some reason, I get this error:
The file music.mp3 is in the same folder as the class I'm running it from, and the code is running in the tick() method. Do anybody have an idea about how I can fix this?
Thanks, Lukas