I know this question has already been asked on this site before, but my question deviates from it a little.
I want to play a .mp3
file without using external Java libraries such as javafx
. Is this possible, and if so, how do you do it? I have nothing against the library javafx
, I just want to know for educational purposes.
I know that with the javax
libraries you can play .wav
files quite easily.
public void playSound() {
try {
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(new File("D:/Music/test.wav").getAbsoluteFile());
Clip clip = AudioSystem.getClip();
clip.open(audioInputStream);
clip.start();
} catch(Exception e) {
e.printStackTrace();
}
}
If you can only play .wav
files with this library, why only that one file type? Was it just the developers choice, or was there some sort of strategy in choosing this one file type? Is there some speed benefit from accessing .wav
files over some other file type?