public class SoundPlayer {
/**
* 播放声音
* @param soundFile 声音文件的相对于SoundPlayer的位置
*/
public static void soundPlay(String soundFile) {
try {
InputStream is = SoundPlayer.class.getResourceAsStream(soundFile);
AudioStream soundStream = new AudioStream(is);
AudioPlayer.player.start(soundStream);
} catch (Exception e) {
e.printStackTrace();
}
}
}
/**
* 播放声音
* @param soundFile 声音文件的相对于SoundPlayer的位置
*/
public static void soundPlay(String soundFile) {
try {
InputStream is = SoundPlayer.class.getResourceAsStream(soundFile);
AudioStream soundStream = new AudioStream(is);
AudioPlayer.player.start(soundStream);
} catch (Exception e) {
e.printStackTrace();
}
}
}
本文介绍了一个简单的Java音频播放器的实现方式。该播放器通过使用AudioStream和AudioPlayer类来播放指定的声音文件。开发者只需提供声音文件相对于SoundPlayer类的位置即可轻松播放音频。
1557

被折叠的 条评论
为什么被折叠?



