我想在我制作的框架中添加声音。 我用Google搜索了一下,发现Java不支持mp3,所以我将磁盘中的歌曲转换为wav文件。 在我的项目中导入 sun.audio.* 和 java.io.* 后,我在框架构造函数中添加这些行
File xx = new File("C:\\Users\\LENOVO\\Desktop\\oss.wav");
InputStream in = new FileInputStream(xx);
AudioStream as = new AudioStream(in);
AudioPlayer.player.start(as);
但它不起作用,我不确定问题是什么,我希望你们能帮我解决这个问题。
最佳答案
You receive errors for unresolved compilation errors.您没有在应该处理的地方处理 Checked Exception
类型。
try {
File xx = new File("C:\\Users\\LENOVO\\Desktop\\oss.wav");
// Must handle FileNotFoundException from new File()!
InputStream in = new FileInputStream(xx);
AudioStream as = new AudioStream(in);
try {
AudioPlayer.player.start(as); // Must handle IOException from start()!
}
catch (IOException ex) { /* Ignore? */ }
}
catch (FileNotFoundException ex) { /* Ignore? */ }
了解更多:
关于java - 添加声音java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24665946/