0

JukeBox

InputStream in = JukeBox.class.getResourceAsStream(s);
InputStream bin = new BufferedInputStream(in);
AudioInputStream ais = AudioSystem.getAudioInputStream(bin);
AudioFormat baseFormat = ais.getFormat();

PlayState

JukeBox.load("/Music/bgmusic.mp3", "music1");
JukeBox.setVolume("music1", -10);
JukeBox.loop("music1", 1000, 1000, JukeBox.getFrames("music1") - 1000);
*javax.sound.sampled.UnsupportedAudioFileException: Stream of unsupported format*
    at java.desktop/javax.sound.sampled.AudioSystem.getAudioInputStream(AudioSystem.java:1014)
    at com.neet.DiamondHunter.Manager.JukeBox.load(JukeBox.java:37)
    at com.neet.DiamondHunter.GameState.PlayState.init(PlayState.java:95)
    at com.neet.DiamondHunter.Manager.GameStateManager.setState(GameStateManager.java:60)

I'm working on a JavaFX project and these codes cause the error and freezing the program.

greg-449
  • 109,219
  • 232
  • 102
  • 145
JustAStudent
  • 1
  • 1
  • 1
  • The Java sound APIs don't support mp3, read the information in the [javasound tag info](https://stackoverflow.com/tags/javasound/info) – greg-449 Dec 11 '19 at 14:11
  • 1
    If I remember correctly, you should be able to use javafx.scene.media.MediaPlayer to play MP3s in JavaFX. See https://stackoverflow.com/a/24353457/942774 – Hendrik Dec 11 '19 at 14:41
  • What hendrik said. javax.sound does not support MP3s, but [javafx.scene.media](https://openjfx.io/javadoc/13/javafx.media/javafx/scene/media/package-summary.html) does. – VGR Dec 11 '19 at 14:45
  • 1
    @VGR While it is certainly possible to get a Service Provider Interface to support MP3 in Java Sound (the info page links to an answer of mine, which in turn, links to a Jar containing it), I'd use the Java-FX functionality in a Java-FX app. Having said that (and having worked with both), the Java Sound API allows the programmer to go significantly beyond the simpler(1) functionality of the Java FX player. 1) .. but more powerful in some ways, in that Java-FX provides an inbuilt audio spectrum analyzer. Java Sound is able to (& wd need to) supply the raw samples before creating an FFT in code. – Andrew Thompson Dec 12 '19 at 01:11

0 Answers0