如何在Java应用程序中播放.mp3和.wav文件?我正在使用Swing。我尝试在互联网上查找类似以下示例的内容:
.mp3
.wav
Swing
public void playSound() { try { AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(new File("D:/MusicPlayer/fml.mp3").getAbsoluteFile()); Clip clip = AudioSystem.getClip(); clip.open(audioInputStream); clip.start(); } catch(Exception ex) { System.out.println("Error with playing sound."); ex.printStackTrace(); } }
但是,这只会播放.wav文件。