如何获取和使用 mp3 而不是 .wav?这适用于 wav 文件,但会出现 mp3 错误。
private String audioFile = "/audio/menu_screen.wav";
public void getSound() {
BufferedInputStream inaudio = new BufferedInputStream(getClass().getResourceAsStream(audioFile));
clip = null;
try {
clip = AudioSystem.getClip();
clip.open(AudioSystem.getAudioInputStream(inaudio));
} catch (LineUnavailableException | UnsupportedAudioFileException | IOException exc) {
exc.printStackTrace(System.out);
}
}
public void playSound(int x) {
if(clip != null){
clip.stop();
}
错误是..
javax.sound.sampled.UnsupportedAudioFileException: could not get audio input stream from input stream
at javax.sound.sampled.AudioSystem.getAudioInputStream(AudioSystem.java:1119)
at frogger.Board.getSound(Board.java:181)
at frogger.Board.muted(Board.java:235)