I was trying to use MP3s instead of wavs and it works fine in NetBeans, but when I build it and try to run the jar there's no sound and I get the NoPlayerException.
background = ImageIO.read(getClass().getResourceAsStream("/background1.png"));
sun = ImageIO.read(getClass().getResourceAsStream("/sun.png"));
cloud = ImageIO.read(getClass().getResourceAsStream("/cloud.png"));
pause = ImageIO.read(getClass().getResourceAsStream("/pause.png"));
soldierchant = AudioSystem.getAudioInputStream(getClass().getResource("/SoldiersChant.wav"));
thebreach = AudioSystem.getAudioInputStream(getClass().getResource("/TheBreach.wav"));
forever = AudioSystem.getAudioInputStream(getClass().getResource("/Forever.wav"));
Format input1 = new AudioFormat(AudioFormat.MPEGLAYER3);
Format input2 = new AudioFormat(AudioFormat.MPEG);
Format output = new AudioFormat(AudioFormat.LINEAR);
PlugInManager.addPlugIn("com.sun.media.codec.audio.mp3.JavaDecoder", new Format[]{input1, input2}, new Format[]{output}, PlugInManager.CODEC);
try {
Player player = Manager.createPlayer(new MediaLocator(getClass().getResource("/TheBreach.mp3").toURI().toURL()));
player.start();
} catch (IOException ex) {
ex.printStackTrace();
}catch (java.net.URISyntaxException x) {
x.printStackTrace();
}catch (javax.media.NoPlayerException c) {
c.printStackTrace();
}
As you can see I'm getting the file from using getResource just like the images and wav that work both in NetBeans and jar. Could this be the problem com.sun.media.codec.audio.mp3.JavaDecoder
I'm grabbing at straws at this point. I've tried putting the MP3 in every folder and doing no / and the full directory.
This is my Exception's getMessage
:
Cannot find a Player for jar:file:/C:/Users/Patrick/Documents/NetBeansProjects/PatBuild8FX/dist/PatBuild8FX.jar!/TheBreach.mp3
I think it is Manager.createPlayer
because when I just create the file alone its fine, but when I try to create a player with it, it doesn't work.
File m = new File("file:/C:/Users/Patrick/Documents/NetBeansProjects/PatBuild8FX/dist/PatBuild8FX.jar/TheBreach.mp3");
System.out.println(m);
System.out.println(Manager.createPlayer(m.toURI().toURL()));
file:\C:\Users\Patrick\Documents\NetBeansProjects\PatBuild8FX\dist\PatBuild8FX.jar\TheBreach.mp3
java.io.IOException: File Not Found
java.io.IOException: File Not Found
Exception in thread "main" javax.media.NoPlayerException: Error instantiating class: com.sun.media.protocol.file.DataSource : java.io.IOException: File Not Found
at javax.media.Manager.createPlayerForContent(Manager.java:1362)
at javax.media.Manager.createPlayer(Manager.java:417)
at javax.media.Manager.createPlayer(Manager.java:332)
at Build8.PanGame.<init>(PanGame.java:75)
at Build8.Main.main(Main.java:30)