我正在尝试使用AudioInputStream和clip方法播放.wav文件。我的代码如下:
fc = new JFileChooser();
fc.setCurrentDirectory(new File(System.getProperty("user.home")));
int result = fc.showOpenDialog(add);
try {
InputStream in = new FileInputStream(fc.getSelectedFile().getAbsolutePath();
System.out.println(fc.getSelectedFile().getAbsolutePath());
try {
AudioInputStream as = AudioSystem.getAudioInputStream(in);
try {
Clip clip = AudioSystem.getClip();
clip.open(as);
Thread.sleep(500);
clip.start();
} catch (LineUnavailableException e) {
e.printStackTrace();
}
} catch (UnsupportedAudioFileException | IOException e) {
System.out.println(e.getMessage());
}
} catch (FileNotFoundException e) {
} `
选择.wav文件时,出现以下错误消息:
不支持标记/重置
任何想法我该如何解决?第一次使用音频文件。
答案 0 :(得分:0)
我建议使用JavaFX MediaPlayer,它更易于使用并且支持更多编解码器。