I have a problem loading my mp3 files in jar. I am trying to load my mp3 to my jar. When I use the code
new Media(new File(Audio.class.getResource(path).toURI()).toURI().toString())
I get an exception says the URI isn't hierarchical, so I search for another solution for that. What I found is using inputstream to load it, and I tried using
new Media(new File(Audio.class.getResourceAsStream(path).toString()).toURI().toString())
I found out that the jar can find my mp3 file but the but it still give an exception
MEDIA_UNAVAILABLE : C:\Users\Brian\Desktop\Boring Fighting Game\Boring Fighting Game\java.io.BufferedInputStream@6d86b085 (The system cannot find the file specified)
at javafx.scene.media.Media.<init>(Media.java:407)
at Something.Audio.load(Audio.java:25)
at Something.BGM.<init>(BGM.java:16)
at MainGame.GameController.init(GameController.java:24)
at MainGame.GameController.<init>(GameController.java:19)
at MainGame.Handler.<init>(Handler.java:24)
at MainGame.Game.<init>(Game.java:38)
at Lancher.Launcher.main(Launcher.java:11)
I'm trying to solve this problem but just can't. Can anyone give me an answer or other solution for this?