// // 播放音乐
public void play(String str) {//str音频文件路径,文件格式是wav
try {
InputStream fis = this.getClass().getResourceAsStream(str);
AudioStream as = new AudioStream(fis);// 音频文件流
theData = as.getData();// 取得音乐文件的数据
} catch (
IOException e) {
System.err.println(e);
}
if (theData != null) {
stop();
ContinuousAudioDataStream cads = new ContinuousAudioDataStream(theData);// 不间断地循环播放
AudioPlayer.player.start(cads);
nowPlaying = cads;
}
}
// 停止播放
public void stop() {
AudioPlayer.player.stop(nowPlaying);
}
09-16
09-16
09-16